SwiftUI: How to build text with subScript and super Script?

1. Any text in ^{} will be treated as superscript.
e.g. => X^{2} -> X²
2. Any text in _{} will be treated as subscript.
e.g. => H_{2} => H₂
var text = Text("pre") + Text("post")//Also
text = text + Text("more text")
Text("X").font(.callout) + Text(2).font(.caption).baselineOffset(6.0)Output => X²

Logic to implement:

1. Iterate throw String for find first ^ or _ 
2. split string add first part as it is.
3. Check if this string followed by {<data>}
4. if yes set the baseline for <data> and ignore ^_{}
5. redo the step 1-4 for second part of string after reducing ^_{<data>}

iOS Developer | Swift | Flutter

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store