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?



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://w3resource.com/swift-programming-exercises/string/swift-string-exercise-1.php