how to replace certain characters in string swift code example
Example 1: javascript delete first character in string
var oldStr ="Hello";
var newStr = oldStr.substring(1); //remove first character "ello"
Example 2: how to replace certain characters in string swift
let aString = "This is my string"
let newString = aString.replacingOccurrences(of: " ", with: "+", options: .literal, range: nil)
Example 3: replace character in swift
extension String {
func withReplacedCharacters(_ oldChar: String, by newChar: String) -> String {
let newStr = self.replacingOccurrences(of: oldChar, with: newChar, options: .literal, range: nil)
return newStr
}
}
Example 4: get certain character from string java
String words = "Hi There"; //creating a string var named 'words'
char index = words.charAt(0); /* setting a variable 'index' to letter
'0' of variable 'words'. In this case, index = 'H'.*/
System.out.println(index); //print var 'index' which will print "H"