Tuesday, August 21, 2012

Xcode how to substring for Noob

There are 3 way to substring in Xcode

Let say Your String is "HelloRabbit"

NSString *aString = @"HelloRabbit"

First Way 

NSString *substring = [aString substringToIndex:7];
You will get: "HelloRab"
It mean you take the first character until the 7th character
Second Way 
NSString *substring = [aString substringFromIndex:5];
You will get "Rabbit"

It mean you take from the 5th character until the end


Third Way NSString *substring = [aString substringWithRange:NSMakeRange(5, 3)];

You will get "Rab"

It mean you start from character 5 and take only 3 character

1 comment:

  1. Amazing, in java its one overloaded method called, guess what? SUBSTRING()
    why oh why...

    ReplyDelete