VOOZH about

URL: https://www.geeksforgeeks.org/swift/how-to-insert-a-character-in-string-at-specific-index-in-swift/

⇱ How to Insert a Character in String at Specific Index in Swift? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to Insert a Character in String at Specific Index in Swift?

Last Updated : 5 Jul, 2022

Swift language supports different types of generic collections and a string is one of them. A string is a collection of alphabets. In the Swift string, we will insert a new character value into the string. To do this task we use the insert() function. This function is used to insert a new character value into the string. It will return a string by inserting a given char into the string.

Syntax:

string.insert(char: Character, at: string.index)

Here string is an object of the String class.

Parameters: This function accepts two parameters that are illustrated below:

  • char: This is a character that will be inserted.
  • at: This is the index where the character will be inserted.

Return Value: This function returns a string by inserting a given character into the string.

Example 1:

Output:

GFG

Example 2:

Output:

GFG

Example 3:

Output:

GeeksforGeeks
Comment
Article Tags:

Explore