w3resource

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


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

Go to:


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

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.