I need to remove spaces from the end of a string. How can I do that?
Example: if string is "Hello "
it must become "Hello"
相关问题
- Textarea Adding Space To Beginning of Text?
- Writing string to XML file without formatting (C#)
- iOS SecKeyRef from NSString
- Change the font size after break line on white spa
- How do I use % character in NSString stringWithFor
相关文章
- CSS white-space nowrap not working
- In Objective-C, how to print out N spaces? (using
- Trim all types of whitespace, including tabs
- Removing trailing white space only for edited line
- Ruby on rails DRY strip whitespace from selective
- Get result from shell script objective-c
- Trim only the first and last occurrence of a chara
- Automatic tooltip when text is trimmed in DataGrid
Another solution involves creating mutable string:
To remove whitespace from only the beginning and end of a string in Swift:
Swift 3
Previous Swift Versions
This will remove only the trailing characters of your choice.
let string = " Test Trimmed String "
For Removing white Space and New line use below code :-
let str_trimmed = yourString.trimmingCharacters(in: .whitespacesAndNewlines)
For Removing only Spaces from string use below code :-
let str_trimmed = yourString.trimmingCharacters(in: .whitespaces)
In Swift
To trim space & newline from both side of the String:
To trim all trailing whitespace characters (I'm guessing that is actually your intent), the following is a pretty clean & concise way to do it:
One line, with a dash of regex.