【发布时间】:2015-12-29 05:43:15
【问题描述】:
我这里用objective-c解析一个句子:
NSString *myString = @“Some words to form a string”;
这是我目前所拥有的:
NSMutableString *firstCharacters = [NSMutableString string];
NSMutableString *lastCharacters = [myString substringFromIndex:[myString length] - 1]
NSArray *arrayOfWords = [myString componentsSeparatedByString:[NSCharacterSet whitespaceCharacterSet]];
for (NSString *word in arrayOfWords) {
if ([word length] > 0) {
NSString *firstLetter = [word substringToIndex:1];
[firstCharacters appendString:lastCharacters];
然后我在这一点上真的很难过。我想 NSLog 重新组合的字符串,使其看起来像这样: "S2e w3s to f2m a s3g"
【问题讨论】:
-
"S2e w3s to f2m a s4g"?
-
一旦你填充了一个NSArray,你可以使用
componentsSeparatedByString:的反向方法:componentsJoinedByString:
标签: objective-c string parsing append