In my program, I need the users to answer the questions. However, if the users typed several spaces after typing the string, how can I eliminate all the spaces after the string in order to compare the answer correctly? I just know the method to trim one space after the string only. Thank you for the help.
Asked
Active
Viewed 482 times
0
-
Which language would the program be written in? – Fred Foo Nov 05 '11 at 14:59
-
@larsmans given the `xcode4.2` tag, I would infer Objective-C. – Matt Ball Nov 05 '11 at 15:03
-
You can edit your question to add the language you're using - both in the description and in the **tags**, the later will help people find your question. – poupou Nov 05 '11 at 20:00
1 Answers
0
Write the code.
NSString* trimmed = [mystring stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

Matt Ball
- 354,903
- 100
- 647
- 710
-
I have used the method mentioned before. However, if i typed the space key for more than one times, than the answer became incorrect. – Peter Lam Nov 06 '11 at 04:11