This question is related to at least:
- Highlighting text with StringReplacePart but also using Style, SubscriptHighlighting text with StringReplacePart but also using Style, Subscript
- How to join two Style[]d stringsHow to join two Style[]d strings
Fortunately it is simpler than the first one and we can apply the methods provided in the second one.
stringBold[s_String, pos_] :=
"" <> MapAt[Style[#, Bold] ~ToString~ StandardForm &, Characters@s, pos]
stringBold["CDABOZPVRYXSWQEGNILUTHMKJF", 7]
The output is a String
with and embedded Box form:
% // InputForm
"CDABOZ\!\(\*StyleBox[\"\\\"P\\\"\", Bold, Rule[StripOnInput, \ False]]\)VRYXSWQEGNILUTHMKJF"
Any specification that MapAt
accepts can be used for parameter pos
:
stringBold["CDABOZPVRYXSWQEGNILUTHMKJF", 2 ;; -3 ;; 3]
However the function cannot be applied to more than once, or to an already styled string:
stringBold[%, 3] (* failure *)