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.](https://www.w3resource.com/w3r_images/swift-string-image-exercise-1.png)
Sample Solution:
Swift Code:
func html_tags(_ tag: String, _ text: String) -> String {
let opening_tag = "<\(tag)>"
let closing_tag = "\(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?
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics