0

我有一个像这样的字符串:

1 this is my first text 2 his is my second 3 this is my third 4 this is my forth etc etc..

每个句子都在数字之间characters like 1 2 3 4 etc

当我点击第一句话时,它需要对其进行剖析并将其复制到剪贴板或其他东西中。我们如何使用 NSScanner 或 NSRange 来计算字符串大小或识别数字字符之间的字符串。

self.multiPageView.text =组合;组合包含上面的文本,所以当我点击第一个句子时,它需要选择并显示一个符合被点击句子的 UIAlertView 是第一个句子,如何通过点击那个句子来检测数字字符之间的句子,比如 ibook。我正在使用核心文本来显示这些类型的文本。

4

2 回答 2

0

使用NSScanner喜欢 -

NSString *yourString = @"1 this is my first text 2 his is my second 3 this is my third 4 this is my forth";

NSScanner *scanner = [NSScanner scannerWithString:yourString];

[scanner scanUpToString:@"1" intoString:nil];
if (![scanner isAtEnd]) {
    [scanner scanUpToString:@"1" intoString:nil];
    NSCharacterSet *charset = [NSCharacterSet characterSetWithCharactersInString:@"2"];
    [scanner scanUpToCharactersFromSet:charset intoString:&yourString];
}
于 2012-05-19T06:57:17.560 回答
0

试试这个,你会得到一个数组,其中会有所有分隔的字符串。你必须用你正在使用的数字填充集合。

    NSString *str1 = @"1 this is my first text 2 his is my second 3 this is my third 4 this is my forth";
    NSMutableCharacterSet *set = [NSMutableCharacterSet controlCharacterSet];
    [set addCharactersInString:@"1"];
    [set addCharactersInString:@"2"];
    [set addCharactersInString:@"3"];
    [set addCharactersInString:@"4"];
    NSArray *arr = [str1 componentsSeparatedByCharactersInSet:set];
于 2012-05-19T07:12:17.253 回答