views:

65

answers:

1

Hi, 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)];
+2  A: 

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)];
Jacob Relkin
great... thanks a lot !
christian Muller
hi Jacob...i really thank you.. as you see i did in my first edit a small mistake. please could u just look through again.. the last two are importent... sorry for the trouble :) after that its done :)The Substring I got... its now only about the indexof(Searchfor,start)
christian Muller
:) I guess I found it... and placed it into my question! You may correct if wrong. thx!!
christian Muller