First, the previous example:
NSString * str1 =[nameinput.text Stringbytrimmingcharactersinset:[nscharactersetwhitespaceandnewlinecharacterset]] ;
NSString * str2 =[passwdinput.text Stringbytrimmingcharactersinset:[nscharactersetwhitespaceandnewlinecharacterset ]];
[Self.delegate loginactioninview:self name:str1 PASSWD:STR2];
Reprinted from: http://blog.csdn.net/aiyongyyy/article/details/8269546
You can use the Stringbytrimmingcharactersinset function in iOS to filter special symbols in a string
First define a nscharacterset, including special symbols that need to be removed.
Nscharacterset *set = [nscharacterset charactersetwithcharactersinstring: @ "@/:; () ¥" ", []{}#%-*+=_\\|~<> $€^? ' @#$%^&* () _+ ' \ "";
Because there are full-width and half-width symbols in the nsstring, some symbols include full-width and half-width
Then call Stringbytrimmingcharactersinset
NSString *trimmedstring = [string stringbytrimmingcharactersinset:set];
Trimmedstring is the filtered string.
----------------------------------------------------------
Http://blog.sina.com.cn/s/blog_5421851501014xif.html
RemoveusernameThe space in the table Newline,nextline
The code is as follows: (three lines of code)
Nscharacterset *whitespace = [NscharactersetWhitespaceandnewlinecharacterset];
NSString *username= [Musernamefield stringvalue];
Username = [usernameStringbytrimmingcharactersinset: whitespace];
Notes:
Stringbytrimmingcharactersinset:
Returns a new string made by removing from both ends of the receiver characters contained in a given character set.
Whitespaceandnewlinecharacterset
Returns a character set containing only the whitespace characters space (u+0020) and tab (u+0009) and the newline and next Line characters (u+000a–u+000d, u+0085).
Alternatively, you can useWhitespacecharactersetReplaceWhitespaceandnewlinecharactersetDifference newline nextline
Whitespacecharacterset
Returns a character set containing only the in-line whitespace characters space (u+0020) and tab (U+0009).
NSString *temptext = [messageTextField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
NSString *text = [temptext stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet ]];
Use the Stringbytrimmingrightcharactersinset method to remove the rightmost space of a string.
C code
- NSLog (@ "%@", [@ "ABC 123" Stringbytrimmingrightcharactersinset:[nscharacterset Whitespacecharacterset]]);
How do I get rid of a string @ "0.012300" at the far right of "0"? This is the typical float format into a string after the form, it is best to remove the rightmost "0".
Here's how to fix it:
C code
- [@ "0.012300" Stringbytrimmingrightcharactersinset:[nscharacterset charactersetwithcharactersinstring:@ "0"];
Remove special symbols in IOS string stringbytrimmingcharactersinset