0

I want to remove the first white space(s) from the given string if any.

Stack over flow does not allow me to type spaces before a word. So, I will explain my requirement by words.

Consider the input word has started with some 4 spaces and a sentence after the white spaces. I should remove the first 4 spaces.

That is, I should start test with each letter from the given string. If the letter is a white space, I should remove that until I will reach a letter/number.

Thanks

Confused
  • 3,846
  • 7
  • 45
  • 72
  • 3
    I believe this has already been answered. Look here: [http://stackoverflow.com/questions/3200521/cocoa-trim-all-leading-whitespace-from-nsstring][1]. [1]: http://stackoverflow.com/questions/3200521/cocoa-trim-all-leading-whitespace-from-nsstring – T. Benjamin Larsen Jan 11 '13 at 10:23

1 Answers1

1

Try this code

NSString *val = @"   Test";
val = [val stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceCharacterSet]];
NSLog(@"%@",val);

Hope it helps you..

P.J
  • 6,547
  • 9
  • 44
  • 74