gpt4 book ai didi

java - iPhone Java 字符串代码到对象 C

转载 作者:行者123 更新时间:2023-12-02 08:31:02 25 4
gpt4 key购买 nike

我有 2 个与对象 C 相关的字符串操作

 // Get the newstring from mystring start at counter
Java: newstring = mystring.substring(counter)

OBJ-C:?

// Get the position from searchstring in mystring
Java: startpos = mystring.indexOf(searchstring)

ObJ-C:?

如果你能帮忙就太好了

谢谢克里斯

编辑:我还有另外两个问题,现在找到了解决方案(这里也适用于其他问题)

  // Get the Position from searchstring in mystring starting at startfrom
Java: location = mystring.indexof(searchfor,startfrom)
OBJ-C: location = [mystring rangeOfString:searchfor options:NSCaseInsensitiveSearch range:NSMakeRange(startfrom, mystring.length-startfrom)].location;


// Get the newstring from mystring start at x and end at y
Java: newstring = mystring.substring(x,y)
OBJ-C: newstring = [mystring substringWithRange:NSMakeRange(x,y-x)];

最佳答案

NSStringsubstringFromIndexrangeOfString 方法与您提到的 Java 方法等效:

newstring = mystring.substring(counter)

将是:

NSString *newString = [mystring substringFromIndex:counter];

startpos = mystring.indexOf(searchstring)

将是:

NSInteger startPos = [mystring rangeOfString:searchstring].location;

newstring = mystring.substring(counter,startfrom)

将是

NSString *newstring = [mystring substringWithRange:NSMakeRange(counter,startfrom)];

关于java - iPhone Java 字符串代码到对象 C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3356684/

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