Get Updates By E-mail 

Subscriber Counter
Article Written By:
Johann Dowa

Objective-C Library For Easier String Formatting/Masking Using Regular Expressions

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.

Submit A Resource

Have you created a useful tutorial, library or tool for iOS development that you would like to get in front of our 300,000+ monthly page views from iOS developers?

You can submit the url here.

The resources we feel will appeal to our readers the most will be posted on the front page.

Comments