开发者

iPhone Java String Code to Object C

I have 2 String Operations I would need relevant in Object 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: ?

Would be great you can help

Thx chris

Edit: I had two other questions and found now the solution (here als for others)

  // 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)];


NSString's substringFromIndex and rangeOfString methods are the equivalent of the Java methods that you mentioned:

newstring = mystring.substring(counter)

would be:

NSString *newString = [mystring substringFromIndex:counter];

and

startpos = mystring.indexOf(searchstring)

would be:

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

and

newstring = mystring.substring(counter,startfrom)

would be

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜