Ios NSString中的子字符串
我使用的是Ios NSString中的子字符串,ios,nsstring,substring,Ios,Nsstring,Substring,我使用的是NSString,我想得到一个子字符串,其中包含字符串的前20个字符。我该怎么做呢?您可以使用子字符串来索引 NSString *str = @"123456789012345678901234"; NSString *subStr = [str substringWithRange:NSMakeRange(0, 20)]; NSString *mystring = @"This is a test message having more than 20 characters"; N
NSString
,我想得到一个子字符串,其中包含字符串的前20个字符。我该怎么做呢?您可以使用子字符串来索引
NSString *str = @"123456789012345678901234";
NSString *subStr = [str substringWithRange:NSMakeRange(0, 20)];
NSString *mystring = @"This is a test message having more than 20 characters";
NSString *newString = [mystring substringToIndex:20];
NSLog(@"%@", newString);
请检查以下内容:
NSString *strTmp = @"This is test string to check substring.";
NSInteger intIdx = 20;
NSLog(@"%@", [strTmp substringToIndex:intIdx]);
这将对你有帮助
干杯 试试这个
NSString *string = @"This is for testing substring from string";
NSInteger intIndex = 20;
NSLog(@"%@", [string substringToIndex:intIndex]);
希望它能帮助您..这太容易用谷歌搜索了。试试这个,从一些声明字符到最后的一些字符中获取特定的20个字符,然后检查我的答案实际上,在子字符串NSString*newString=myString.length>20之前检查字符串长度是一种很好的做法?[mystring substringToIndex:20]:mystring;
NSString *string = @"This is for testing substring from string";
NSInteger intIndex = 20;
NSLog(@"%@", [string substringToIndex:intIndex]);