gpt4 book ai didi

ios - 如何从字符串中获取日期、时间和金额

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:55:51 25 4
gpt4 key购买 nike

我有

NSstring *str = @"Existing applications can be improved or extended on 11-01-2014 at 4 PM for 120$ ";

我想从上面的字符串中获取日期、时间和金额。上面的字符串我正在尝试动态获取..

我试过的是

NSArray *arySeperator = [result componentsSeparatedByString:@" "];
for(int i=0;i< [arySeperator count];i++)
{

}

无法继续..

请就如何进一步进行提供任何帮助或建议?

最佳答案

试试这个

 NSString *str = @"Existing applications can be improved or extended on 11-01-2014";
NSString *aStrDate = [str substringFromIndex:[str rangeOfString:@" " options:NSBackwardsSearch].location + 1];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
// this is imporant - we set our input date format to match our input string
// if format doesn't match you'll get nil from your string, so be careful
[dateFormatter setDateFormat:@"dd-MM-yyyy"];
NSDate *dateFromString = [[NSDate alloc] init];
// voila!
dateFromString = [dateFormatter dateFromString:aStrDate];

关于ios - 如何从字符串中获取日期、时间和金额,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25761473/

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