iPhone dev: Replace uppercase characters in NSString with space and downcase

不想你离开。 提交于 2019-12-04 20:35:49
Thomas Joulin

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]);

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 :)

Draco

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'?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!