0

I have:

NSString *promise = @"thereAreOtherWorldsThanThese";

which I'm trying to transform into the string:

@"There are other worlds than these"

I'm guessing this is a regex job, but I'm very new to Objective C, and have so far had no luck. I would greatly appreciate any help!

thomax
  • 9,213
  • 3
  • 49
  • 68

3 Answers3

3

I'd use GTMRegex (http://code.google.com/p/google-toolbox-for-mac/), for example:

NSString *promise = @"thereAreOtherWorldsThanThese";
GTMRegex *regex = [GTMRegex regexWithPattern:@"([A-Z])"];
NSLog(@"%@", [[regex stringByReplacingMatchesInString:promise
                     withReplacement:@" \\1"] lowercaseString]);
penfold
  • 1,523
  • 1
  • 14
  • 21
Thomas Joulin
  • 6,590
  • 9
  • 53
  • 88
0

Without using any libraries you can use this NSString category I posted. Just perform lowerCaseString on the string array. How do I convert an NSString from CamelCase to TitleCase, 'playerName' into 'Player Name'?

Community
  • 1
  • 1
Draco
  • 262
  • 5
  • 12
0

As for removing the uppercase letters you can simply use lowercaseString on NSString.

But as for inserting spaces just before an uppercase letter, I would agree that it would be a job for a regex, and sadly, my regex fu is rubbish :)

Jasarien
  • 58,279
  • 31
  • 157
  • 188