How to Append a String to Another String in Swift?
Last Updated :
05 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 add a string value to another string. To do this task we use the append() function. This function is used to add a string value to another string. It will return the appended string.
Syntax:
string.append(str: String)
Here string is an object of the String class.
Parameters: This function accepts a parameter that is illustrated below:
- str: This is a string that will be joined to the string.
Return Value: This function returns an appended string.
Example 1:
Swift
import Swift
var string1 = "Geeks"
var string2 = "forGeeks"
string1.append(string2)
print (string1)
|
Output:
GeeksforGeeks
Example 2:
Swift
import Swift
var string = "GeeksforGeeks"
string.append( " is a" )
string.append( " CS Portal." )
print (string)
|
Output:
GeeksforGeeks is a CS Portal.
Share your thoughts in the comments
Please Login to comment...