gpt4 book ai didi

iphone - 如何截取 NSString 的部分内容?

转载 作者:行者123 更新时间:2023-12-03 17:28:16 25 4
gpt4 key购买 nike

@"/News/some news text/" 
@"/News/some other news text/"
@"/About/Some about text/"
@"/Abcdefg/Some abcdefg text/some more abcdefg text"

如何剪掉字符串的第一部分,以便最终得到以下字符串?

@"/News/"
@"/News/"
@"/About/"
@"/Abcdefg/"

最佳答案

使用componentsSeparatedByString:来分解字符串:

NSArray *components=[string componentsSeparatedByString:@"/"];
if ([components count]>=2) {
// Text after the first slash is second item in the array
return [NSString stringWithFormat:@"/%@/",[components objectAtIndex:1]];
} else {
return nil; // Up to you what happens in this situation
}

关于iphone - 如何截取 NSString 的部分内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3838734/

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