Comparative content bool isequal= "string1 isequaltostring:string2];
Compare pointer addresses (STRING1==STRING2)
Compare String size ascending order
Nscomparisonresult result =[string10 caseinsensitivecompare:string11];
To find the string lengthNSlog (@ "%d", [string11 length]);
String ConversionsNSLog (@ "upper:%@", [string11 uppercasestring]); uppercaseNSLog (@ "lower:%@", [string11 lowercasestring]); lowercaseNSLog (@ "capital:%@", [string11 capitalizedstring]); Capitalize first letter
converting basic data Typesnsstring *[email protected] "3,14";float PPI=[STRING13 Floatvalue];
String Conversion Arraynsstring* string14 [email protected] "ABC BCD XYZ";nsarray*array=[string14 componentsseparatedbystring:@ ""];(quotation marks are separated by a space)NSLog (@ "array:%@", array);
Intercept StringNsstring*string1=[string15 Substringtoindex:2]; does not contain a second (to that)nsstring*string2=[string15 Substringfromindex:2:]; contains the second bit (starting from that bit)Nsrange range={4,2};nsstring *substring=[string15 Substringwithrange:range];
//concatenation of stringsnsstring*appstring2=[string16 stringbyappendingformat:@ "%@", String17];nsstring*appstring2=[string16 Stringbyappendingstring:string17];
Find Stringnsstring *[email protected] "ABCDEFGH=_BLANKXYZ"nsrange range=[link rangeofstring;@ "Fgh=_blank"];if (range1.location!=nsnotfound) {//(Nsnotfound=nsintegermax)NSLog (@ "founded");}
variable Stringmsmutablestring *mutablestring=[[nsmutablestring alloc] initwithformat:@ "abc"]Increase[mutableString1 insertstring:@ "XYZ" atindex:3];Change[mutablestring replacecharactersinrang:nsmakerange (0,3) withstring:@ "EFG"];Delete[mutableString1 Deletecharactersinrange:nsmakerange (0,3)];
calculates the size of the text string
-(Cgsize) Sizewithtext: (NSString *) text font: (Uifont *) font maxSize: (cgsize) maxSize
{
Nsdictionary *attrs = @{nsfontattributename:font};
return [text boundingrectwithsize:maxsize options:nsstringdrawinguseslinefragmentorigin attributes:attrs context: Nil].size;
}
OC Traversal string
1) Find the way to (this way suitable for all the format of the substring, recommended to use)
NSString *newstr [email protected] "abdcdddccdd00 everyone good Oh";
NSString *temp = nil;
for (int i =0; i < [newstr length]; i++)
{
temp = [Newstr substringwithrange:nsmakerange (I, 1)];
NSLog (@ "The first%d words are:%@", i,temp);
}
(2) traversing a string by traversing a character (only for strings that do not contain Chinese)
NSString *newstr = @ "abdcdddccdd00";
for (int i =0; i < [newstr length]; i++)
{
NSLog (@ "%d characters are:%@", I, [Newstr characteratindex:i]);
}
Foundation framework--nsstring Class string common operations