gpt4 book ai didi

objective-c - 我怎样才能将 NSString 子串到字符的第三次出现?

转载 作者:搜寻专家 更新时间:2023-10-30 20:01:05 25 4
gpt4 key购买 nike

我想统计重复3次的','字符和子串。

输入:

9,1,2,3,9

输出:

9,1,2

最佳答案

我很确定特定的东西不会有内置方法。在我的脑海中:

for(unsigned int i = 0; i < [string length]; ++i)
{
if([string characterAtIndex:i] == ',')
{
++commaCount;
if(commaCount == 3)
{
return [string substringWithRange: NSMakeRange(0, i)];
}
}
}

http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html

Apple 引用文档通常是一个很好的起点。

关于objective-c - 我怎样才能将 NSString 子串到字符的第三次出现?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7504115/

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