If only spaces in the string are replaced, use the nsstring
The stringbyreplacingoccurrencesofstring function is OK.
Eg:
Nsstring * Email = [emailori stringbyreplacingoccurrencesofstring: @ "" withstring: @ ""];
Then, sometimes, we only need to remove the spaces at the beginning and end of a string (because this is often input accidentally by the user). If there is a space in the middle of the input, you can prompt that the email format is incorrect ~
At this time, you need to use the following function:
Stringbytrimmingcharactersinset:
Eg:
Email = [email stringbytrimmingcharactersinset: [nscharacterset
Whitespacecharacterset];
Just remove the spaces on both sides.
Another function is to remove spaces and press enter and replace the red text in the above text. Of course, there are some other functions to read the document!
Whitespaceandnewlinecharacterset
You need it.
PS: otherwise, if people accidentally enter a space in front and cannot find the problem, it is estimated that they will be depressed. If they get mad, they will go to appstore to evaluate a star ...!