w3resource

Swift String Exercises: Draw a HTML string as bold or italic text

Swift String Programming: Exercise-1 with Solution

Write a Swift program to draw a HTML string as bold or italic text.

Pictorial Presentation:

Flowchart: Swift String Exercises - Draw a HTML string as bold or italic text.

Sample Solution:

Swift Code:

func html_tags(_ tag: String, _ text: String) -> String {
    let opening_tag = "<\(tag)>"
    let closing_tag = ""
    return "\(opening_tag)\(text)\(closing_tag)"
}
print(html_tags("i", "HTML"))
print(html_tags("b", "Swift"))

Sample Output:

<i>HTML
<b>Swift

Swift Programming Code Editor:

Improve this sample solution and post your code through Disqus

Previous: Swift String Exercises Home.
Next: Write a Swift program to insert a given string to another given string where the second string will be in the middle of the first string.

What is the difficulty level of this exercise?



Follow us on Facebook and Twitter for latest update.