我加入串入一个像这样的pickerView字符串的字符:可可xcode4.3隐藏
NSString *string = [NSString stringWithFormat:@"%@ %@", xxx, xxx];
[pickerViewObjects addObject:string];
我想要做的是隐藏的字符串的第一部分,或者有使用的东西像charachterAtIndex因为我的字符串的第一部分具有字符的具体数目将是有益的。
我加入串入一个像这样的pickerView字符串的字符:可可xcode4.3隐藏
NSString *string = [NSString stringWithFormat:@"%@ %@", xxx, xxx];
[pickerViewObjects addObject:string];
我想要做的是隐藏的字符串的第一部分,或者有使用的东西像charachterAtIndex因为我的字符串的第一部分具有字符的具体数目将是有益的。
使用这种方法来获得“(空格)约翰”
NSString *string = @"Hello John";
NSUInteger spacePosition = [string rangeOfString:@" "].location;
NSMutableString *newString = [[NSMutableString alloc]init ];
for (int i=0; i<spacePosition; i++)
[newString appendString:@" "];
NSString *otherPartofString = [string substringFromIndex:(spacePosition)];
[newString appendString:otherPartofString];
NSLog(@"new String is '%@'",newString);
[newString release];
您可以使用[string substringWithRange:NSMakeRange(start, count)]
,这样你只会得到,你可以用来显示一个新的字符串。
,你可以这样做:
找到空间两个字符串之间这样的位置:
NSUInteger spacePosition = [字符串rangeOfString:@”“] .location
然后使用:
的NSString * otherPartofString = [字符串substringFromIndex:(spacePosition + 1)];
我想隐藏的字符前的空格不要删除它,反正THX。 – shakyeb 2012-08-08 10:31:48
要隐藏这样的空间之前的所有字符: “你好,约翰”转换为 “(空格)约翰” 或 “XXXXX约翰”? – Bhupendra 2012-08-08 10:54:25
(空格)John – shakyeb 2012-08-08 11:01:44