To remove the first character of a string in Swift, you can use string slicing starting from index 1.
In this example,
str1
with a value of "Hello World"
.let str1 = "Hello World"
let modifiedStr1 = String(str1.dropFirst())
print("Modified string is: \(modifiedStr1)")
Modified string is: ello World
In this example,
str2
with a value of "apple"
.let str2 = "apple"
let modifiedStr2 = String(str2.dropFirst())
print("Modified string is: \(modifiedStr2)")
Modified string is: pple
In this tutorial, we learned How to Remove First Character in a String in Swift language with well detailed examples.