Search code examples
iphoneios4removing-whitespace

NSRegularExpression to remove white space


I need a little kickstart on regex on the iPhone. Actually I am dealing with UITextField.text. If the value of the text is empty and if the value already exist, I can able to deal it. But, if the value is simply white spaces, I do not want to use it. So, if the value is like " " or " folder", I want the value to be "" and "folder" respectively.

I planned to use NSRegularExpression to remove the white space and went through the documents. But it was little confusing. So, help me to come out of the problem of removing white space from the given string. Thank you in advance.


Solution

  • Edit: you need to trim string, so no regular expression is needed, simply use:

    [str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];