Swift String remove()

The remove() method removes a character in the string at the specified position.

Example


remove() Syntax

The syntax of the string remove() method is:

string.remove(at: i)

Here, string is an object of the String class.


remove() Parameters

The remove() method takes only one parameter.

  • i - index of the character to remove

remove() Return Values

  • returns a character that was removed from string

Example: Swift string remove()

Output

Before Removing: Hello, World!
After Removing: Hello, World
Removed Character: !

Here, we have removed "!" from the message string. The removed character is stored in the removed variable.