1, find
Nsstring*str = @ "BFJFNNFKANFKNF";
Nsrange range = [str rangeofstring:@ "111"];
if (range.location = = Nsnotfound)
{
NSLog (@ "not found in STR 111");
}else {
NSLog (@ "Search range%@", Nsstringfromrange (range));
}
The following method is used later in the ios8.0 and is also judged to include a string
BOOL result = [@ "123" containsstring:@ "2"]; 2. Interception
NSSTRING*BSTR = [str substringwithrange:nsmakerange (loc,2)];
The LOC represents the beginning of the first few characters, 2 means intercepting two characters;
to intercept n characters starting from the first character: [str substringtoindex:n]; intercept from the first n+1 to the end of the string: [Str substringfromindex:n];
3, Split
Nsstring*string =@ "Facing the Sea/spring";
Nsarray*array = [string componentsseparatedbystring:@ '/'];//an array of 2 elements separated from characters/
NSLog (@ "array1 = =%@", [array firstobject]);
NSLog (@ "array2 = =%@", [array lastobject]); Print Result: Array1 = face toward the sea, Array2 = Spring 4. Replace
Nsstring*str =@ "12345678";
NSSTRING*REPLACEDSTR = [str stringbyreplacingoccurrencesofstring:@ "345" withstring:@ "string to be replaced"];
NSLog (@ "REPLACEDSTR = =%@", replacedstr);
Print results:
Replacedstr = = 12 you want to replace the string 678 5. Verify
NSSTRING*STR1 =@ "http:www.baidu.com";
BOOL a = [str1 hasprefix:@ "http"];//whether to start with HTTP
BOOL B = [str1 hassuffix:@ "com"];//file path ends with COM
NSLog (@ "A =====%d, b = =%d", a,b);
Print results:
A ===== 1, b = = 1 6. Turn into numbers
[Str boolvalue];
[Str IntegerValue]; 7. Change the case of a string
nsstring* str2 =@ "BeiJING";
Nsstring*da = [str2 uppercasestring];//converted to uppercase
Nsstring*xiao = [str2 lowercasestring];//to lowercase
Nsstring*shouda = [str2 capitalizedstring];//first letter uppercase, remaining lowercase
NSLog (@ "\ n Capital ==%@\n lowercase = =%@\n First letter uppercase Other lowercase = =%@", Da,xiao,shouda);
Print results:
Capital ==beijing
lowercase = = Beijing
First letter Uppercase Remaining lowercase = = Beijing 8. Encode, decode
Coding:
Nsstring*hstr =@ "Hello";
nsstring*hstring = [Hstr stringbyaddingpercentescapesusingencoding:nsutf8stringencoding];
NSLog (@ "hstring = =%@", hstring);
Decoding:
NSSTRING*STR3 =@ "\u5982\u4f55\u8054\u7cfb\u5ba2\u670d\u4eba\u5458\uff1f";
NSSTRING*STR5 = [str3stringbyreplacingpercentescapesusingencoding:nsutf8stringencoding];
NSLog (@ "string = =%@", STR5);
Print results:
hstring = =%e4%bd%a0%e5%a5%bd%e5%95%8a
String = = How to contact customer service personnel.