0

I have NSString:

sessid=os3vainreuru2hank3; __ubic1=MzcxMzjMDYuNjk0NDA1Mzc%3D; auto_login=123; sid=kep8efpo7; last_user=123;

I need get just:

__ubic1=MzcxMzjMDYuNjk0NDA1Mzc%3D; auto_login=123; interpals_sessid=kep8efpo7; last_user=123;

But count of characters past sessid may vary

Thanks! Sorry for simple question

Alexander
  • 627
  • 2
  • 11
  • 23

3 Answers3

2

This should do the trick.-

NSRange range = [yourString rangeOfString:@" "];
if (NSNotFound != range.location) {
    yourString = [yourString substringFromIndex:(range.location + 1)];
}

Basically, you get the index for the first space character, and then the substring from that index to the end.

ssantos
  • 16,001
  • 7
  • 50
  • 70
1

You'll need at least one character you can search for. Looks like that double underscore will work.

NSRange stringStart = [originalString rangeOfString:@"__"];
NSString *extractedString = [originalString substringWithRange:NSMakeRange(stringStart.location, originalString.length - stringStart.location)];

That should get you what you need!

joeByDesign
  • 133
  • 8
1
NSMutableArray* array = [[originalString componentsSeperatedByString:@";"] mutableCopy];
[array removeObjectAtIndex:0];
NSString* newString = [array componentsJoinedByString:@";"];

I assume you mistyped interpals_sessid with sid

Peteee24
  • 510
  • 4
  • 8