I’ve mentioned some libraries for making it easier to perform string validation such as PMValidation and here’s a library from Flavio Caetano that allows you to easily mask and format your NSString data called NSStringMask.
Formatting is done using a regular expression that you can supply directly to the library or you can supply a NSRegularExpression. You can also supply placeholder data to fill in any empty spaces.
As the readme explains:
suppose you have the string 12345678 and want to format it as a Social Security Number (which regex pattern is \d{3}-\d{2}-\d{3}). With NSStringMask, all you have to do is [NSStringMask maskString:@”12345678″ withPattern:@”(\\d{3})-(\\d{2})-(\\d{3})”] and the result will be “123-45-678“.
You can find NSStringMask on Github here.
A handy library to have around if you find yourself needing to do some string formatting.
- Open Source: Lightweight And Fast Regular Expressions Library
- Free Tool For Building iOS Regular Expressions (NSRegularExpression) That Actually Work
- Goodies From Google To Accelerate iPhone Development
- Objective-C Library Of Matcher Objects For OCUnit, GHUnit, Cedar, More For Easier Testing
- Best Resources In iOS Development May 23rd 2011
Original article: Objective-C Library For Easier String Formatting/Masking Using Regular Expressions
©2013 iOS App Dev Libraries, Controls, Tutorials, Examples and Tools. All Rights Reserved.