1. Intercepting strings
nsstring*string=@"SDFSFSFSADFSDF";string= [stringSubstringtoindex:7];//intercept the string after the drop Mark 7NSLog (@"The Intercept value is:%@",string); [stringSubstringfromindex:2];//intercept the string before the drop Mark 2NSLog (@"The Intercept value is:%@",string);
2. Matching strings
nsstring*string=@"SDFSFSFSADFSDF"; Nsrangerange= [Stringrangeofstring:@"F"];//match the resulting subscriptNSLog (@"rang:%@", Nsstringfromrange (range));string= [stringSubstringwithrange:range];//A string that intercepts the scope classNSLog (@"The Intercept value is:%@",string);
3. Separating strings
nsstring*string=@"SDFSFSFSADFSDF"; Nsarray*array = [stringComponentsseparatedbystring:@"A"];//an array of 2 elements separated from character aNSLog (@"array:%@", array);//The result is ADFSFSFS and dfsdf1. Intercept stringNSString*string=@"SDFSFSFSADFSDF";string= [stringSubstringtoindex:7];//intercept the string after the drop Mark 7NSLog (@"The Intercept value is:%@",string); [stringSubstringfromindex:2];//intercept the string before the drop Mark 2NSLog (@"The Intercept value is:%@",string);
4. Separating strings, dividing strings into groups
nsstring*String =@ "sdfsfsfsadfsdf"; Nsarray *array = [string componentsseparatedbystring:@ "A"// An array of 2 elements separated from character a NSLog (@ "array:%@"// The result is ADFSFSFS and Dfsdf .
5, the array turns into a string
Nsarray *array = @[@ "a",@ "b",@ "C" ,@ "d",@ "e",@ "F "*string = [Array componentsjoinedbystring:@","];, As a delimiter
6, filter strings, filter all non-character symbols
Nscharacterset *donotwant = [Nscharacterset charactersetwithcharactersinstring:@ "" @""]; NSLog (@ "humstr is%@", hmutstr); return hmutstr;
Just make a record! If there is something wrong, please feel free!
iOS Development--nsstring Operations