gpt4 book ai didi

iphone - Objective-C : How to grab a number after a sub string from string

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:23:50 25 4
gpt4 key购买 nike

我有一个很长的字符串如下

Please plan to attend to provide upgrade to existing code

morning meeting to acoomdate bum team members

Meeting Number: 457 231 123


To join this meeting

  1. go to http://domainname.com
  2. enter password

现在我想在文本“ session 号”之后获取号码即 457 231 123

请帮忙。谢谢

编辑

假设我有一个字符串

NSString *myString = @"Please plan to attend to provide upgrade to existing code morning meeting to acoomdate bum team members  Meeting Number: 457 231 123 ----------------------------------------------------- to join this meeting ------------------------------------------------------  1. go to http://domainname.com 2. enter password"

最佳答案

你想要NSScanner .它专门用于此类事情。

NSScanner *scanner = [NSScanner scannerWithString:yourString];
NSString *prefix = @"Meeting number: ";
NSString *numbers;
[scanner scanUpToString:prefix intoString:NULL];
[scanner scanString:prefix intoString:NULL];
[scanner scanUpToCharactersFromSet:[NSCharacterSet newlineCharacterSet] intoString:&numbers];
// numbers now contains the numbers you want.

(这可以通过执行 scanUpToCharactersFromSet:[NSCharacterSet decimalDigitCharacterSet] 而不是带有前缀字符串的两行来简单地修改以查找任何数字。)

关于iphone - Objective-C : How to grab a number after a sub string from string,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10291881/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com