Tuesday 15 February 2011

ios - Saving parsing and striping metadata in NSString -



ios - Saving parsing and striping metadata in NSString -

i have dynamic string getting in app. 1 illustration below. (??? = n1 + n2 + n3 + n4) in example, numbers supposed subscripts. since know piece of info manually drawing them nsbaselineoffsetattributename fine. in future there strings have set subscript dynamically strings. looking way pass subscript info in string , parsing info , striping away part of string because it's metadata.

how should go this? can inquire guy on backend pass me string in shape want. looking suggestions.

thanks.

self.statement1string = [nsstring stringwithformat:@"??? = n1 + n2 + n3 + n4"]; nsinteger start = 0; (nsstring *component in [self.statement1string componentsseparatedbystring:@" "]) { nsrange checkrange = nsmakerange(start, self.statement1string.length - start); nsrange range = [self.statement1string rangeofstring:component options:0 range:checkrange]; nslog(@"range %@ string %@", nsstringfromrange(range), component); qwzterm *term = [[qwzterm alloc] initwithrangevalue:[nsvalue valuewithrange:range]]; term.termstring = [nsstring stringwithformat:@"%@",component]; [temparray addobject:term]; start = range.location + range.length; } [self.statementtextstorage setattributes:@{nsfontattributename : [uifont fontwithname:@"source sans pro" size:30] , nsbaselineoffsetattributename : @-10} range:nsmakerange(7, 1)]; [self.statementtextstorage setattributes:@{nsfontattributename : [uifont fontwithname:@"source sans pro" size:30] , nsbaselineoffsetattributename : @-10} range:nsmakerange(12, 1)]; [self.statementtextstorage setattributes:@{nsfontattributename : [uifont fontwithname:@"source sans pro" size:30] , nsbaselineoffsetattributename : @-10} range:nsmakerange(17, 1)]; [self.statementtextstorage setattributes:@{nsfontattributename : [uifont fontwithname:@"source sans pro" size:30] , nsbaselineoffsetattributename : @-10} range:nsmakerange(22, 1)];

ios parsing nsstring

No comments:

Post a Comment