tags:

views:

215

answers:

9

I want to separate a string with the occurrence of the Uppercase letters. Suppose I have an string like "IAmABoy".I want the resulting strings like

I
Am
A
Boy.

How to do this? Is there any sample code? Please show me the way to do this.

A: 

Plz help me.I need it very urgently,plz anybody.

XcoderMi2
A: 

I'd suggest importing a Regex library or taking a look at NSScanner.

brianegge
A: 

Thanx for your reply.Can you provide me any sample codes?

XcoderMi2
A: 

look into RegexKitLite

Jasarien
A: 

I can find nothing from you answers.Please show me the way.

XcoderMi2
A: 

Try using -rangeOfCharacterFromSet: and splitting the string based on where you find the upper-case characters.

Graham Lee
A: 

Thanx Graham Lee for your reply.Can you provide me some sample codes.

XcoderMi2
A: 

What about something simple like just iterating over each character? Assuming inputString and outputString are NSStrings something like this should work:

  NSUInteger length = [inputString length];
  for (NSUInteger i = 0; i < length; i++)
  {
    char c = [inputString characterAtIndex:i];
    if (i > 0 && c >= 65 && c <=90)
    {
      [outputString appendFormat:@"\n%c", c];
    }
    else
    {
      [outputString appendFormat:@"%c", c];
    }
  }
carson
A: 

Thanx Carson for you reply.But the line

[outputString appendFormat:@"\n%c", c];

througing some exception.I have modify your code to the following one and it seems to be working for me.


NSString *inputString=@"IAmABoy"; NSString *outputString; NSString *string=@""; NSUInteger length = [inputString length]; for (NSUInteger i = 0; i < length; i++) { char c = [inputString characterAtIndex:i]; if (i > 0 && c >= 65 && c <=90) { //[outputString appandFormate:@"\n%c", c]; outputString=[NSString stringWithFormat:@"%c", c]; string = [NSString stringWithFormat:@"%@%@%@",string,@" ",outputString]; NSLog(@"%@", string); } else { //[outputString appendFormat:@"%c", c]; outputString=[NSString stringWithFormat:@"%c", c]; //NSLog(@"%@",outputString); string = [NSString stringWithFormat:@"%@%@",string,outputString]; NSLog(@"%@", string); } }


Thanx once again to all for your cooperations and help.

XcoderMi2