WepsTech
The world of development
If you are looking for the modification of string into the different format
, then you are on the correct post. Because here I am going to tell you the concept that how can modify
your entire string into the swift language
. This protocol will help you bring you out from the different situation.
Let’s suppose you want to change any character with any character
into the entire string then you can follow the below code.
func change_string() {
var my_string = "abcd_fgh"
my_string = my_string.replacingOccurrences(of: "_", with: "e", options: NSString.CompareOptions.literal, range: nil)
}
This function is useful for replace the _
with character e
. in the same manner if you want to remove the _
or any other character or spacial character
from the string then you can replace that character with the blank space
. Below you can find the example method.
func change_string() {
var my_string = "abcd_fgh"
my_string = my_string.replacingOccurrences(of: "_", with: "", options: NSString.CompareOptions.literal, range: nil)
}
This function will help you with removing the character from the string. There is another different term you should know about the sting which is given as below.
Swift uses backslash to escape double quotes. Here is the list of escaped special characters in Swift:
\0 (null character)
\\ (backslash)
\t (horizontal tab)
\n (line feed)
\r (carriage return)
\" (double quote)
\' (single quote)
If you want a deep knowledge about the string then go through by the link – String Literals
Good Luck 🙂 Happy Coding