如何从原始字符串中删除字符串
即。我的字符串是,
series0001.0001
or
series0010.0101
or
series0110.0050
从这个字符串我必须将其转换为
expected result
Series 1 1
Series 10 101
Series 110 50
这是我正在做的代码
NSArray * words = [sym.data componentsSeparatedByString:@"\r\n\r\n"];
NSLog(@"words are %@",words);
NSString *strSeriesAndLabelDetail = [words objectAtIndex:0];
NSLog(@"strSeriesAndLabelDetail is %@",strSeriesAndLabelDetail);
NSArray *wordsToSeparateSeriesAndLabel = [strSeriesAndLabelDetail componentsSeparatedByString:@"."];
NSLog(@"wordsSeriesLabel are %@",wordsToSeparateSeriesAndLabel);
strLabelNumber = [wordsToSeparateSeriesAndLabel objectAtIndex:1];
NSLog(@"strLabelNumber are %@",strLabelNumber);
strSeriesNumber = [wordsToSeparateSeriesAndLabel objectAtIndex:0];
NSLog(@"strSeriesNumber is %@",strSeriesNumber);
当前OutPut是:
words are (
"series0001.0003",
"Use the Sort-a-Cord app to read this code or visit www.sortacord.com to get your Sort-a-Cords."
)
strSeriesAndLabelDetail is series0001.0003
wordsSeriesLabel are (
series0001,
0003
)
strLabelNumber are 0003
strSeriesNumber is series0001
任何人都可以帮助我。提前感谢任何建议。
答案 0 :(得分:1)
一种方法:
NSString *stringToModify = @"series0110.0050";
stringToModify = [stringToModify stringByReplacingOccurrencesOfString:@"series" withString:@""];
NSArray *array = [stringToModify componentsSeparatedByString:@"."];
NSString *finalString = [NSString stringWithFormat:@"Series %d %d", [[array objectAtIndex:0] integerValue], [[array objectAtIndex:1] integerValue]];
NSLog(@"%@",finalString);
请注意,它可能会根据您的需要进行修改。我以为你总是有“系列”来寻找。