w3resource

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

Swift String Programming: Exercise-8 with Solution

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

Swift Programming Code Editor:

Improve this sample solution and post your code through Disqus

Previous: 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.

What is the difficulty level of this exercise?



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/swift-programming-exercises/string/swift-string-exercise-8.php