-1

请告诉我如何从由某个字符分隔的单个字符串中提取子字符串?

/ 2132321321/34 3/0 /

谢谢

4

1 回答 1

4

您可以通过执行将字符串分隔为数组...

NSString *myString = @"/ 2132321321/34 3/0 /";

NSArray *strings = [myString componentsSeparatedByString:@"/"];

这将有一个包含所有字符串的数组,例如...

[@" 2132321321",
 @"34 3",
 @"0 "];

然后你可以做...

for (NSString *string in strings) {
    NSLog(@"%i", [string length]);
    // You can do what you want in here.
}

这将打印所有长度。

于 2012-12-17T09:07:05.277 回答