I have a couple of strings. Some have a whitespace in the beginning and some not. I want to check if a string begins with a whitespace and if so remove it.
相关问题
- CALayer - backgroundColor flipped?
- how to split a list into a given number of sub-lis
- Core Data lightweight migration crashes after App
- back button text does not change
- Generate string from integer with arbitrary base i
相关文章
- 现在使用swift开发ios应用好还是swift?
- JSP String formatting Truncate
- TCC __TCCAccessRequest_block_invoke
- xcode 4 garbage collection removed?
- Selecting only the first few characters in a strin
- Unable to process app at this time due to a genera
- How can I add media attachments to my push notific
- didBeginContact:(SKPhysicsContact *)contact not in
You could use the stringByTrimmingCharactersInSet NSString method with the whitespaceAndNewlineCharacterSet NSCharacterSet as such:
This will remove only the leading white space.
output
There is method for that in NSString class. Check
stringByTrimmingCharactersInSet:(NSCharacterSet *)set
. You should use[NSCharacterSet whitespaceCharacterSet]
as parameter:I wrote a quick macro to reduce the amount of code needed to be written.
Step 1: Edit your app's PCH file, this should be named Project-Name-Prefix.pch
Step 2: Enjoy writing way less code when you want to trim a string