How to rationalize real number in string?

Considering we have:

in = "F 18/10"


How can I make this to be:

Thanks!

• You want the output to be a String too, correct? – Mr.Wizard Jul 16 '15 at 9:54

1 Answer

Please try:

StringReplace[in,
d1 : DigitCharacter .. ~~ "/" ~~ d2 : DigitCharacter .. :>
"\!$$\*FractionBox[\(" ~~ d1 ~~ "$$, $$" ~~ d2 ~~ "$$]\)"]

• When trying to edit the output I see an error: INTERNAL SELF-TEST ERROR: MathEditCells2|c|1411 Click here to find out if this problem is known, and to help improve the Wolfram System by reporting it to Wolfram Research. – SuTron Jul 16 '15 at 12:21
• @SuTron Unfortunately that's a bug in the Front End. If you manually create the same string in an Input cell, evaluate it, and try to edit the output I think you will get the same error. :-( – Mr.Wizard Jul 16 '15 at 12:36