w3resource

Swift String Exercises: Accept two strings and return their concatenation, except the first char of each string


Write a Swift program that accept two strings and return their concatenation, except the first char of each string. The given strings length must be at least 1.

Pictorial Presentation:

Flowchart: Swift String Exercises -  Accept two strings and return their concatenation, except the first char of each string.

Sample Solution:

Swift Code:

func concate_str(_ str1: String, _ str2: String) -> String {
    var part1 = str1.characters
    var part2 = str2.characters
    part1.removeFirst()
    part2.removeFirst()
    
    return String(part1)+String(part2)
}
print(concate_str("Swift", "Examples"))
print(concate_str("HTML", "CSS"))

Sample Output:


wiftxamples
TMLSS

Go to:


PREV : Write a Swift program that accept two strings of different length and return a string of the form short+long+short.
NEXT : Write a Swift program to move the first two characters of a given string to the end. The given string length must be at least 2.

Swift Programming Code Editor:

Improve this sample solution and post your code through Disqus

What is the difficulty level of this exercise?



Follow us on Facebook and Twitter for latest update.