0

I have the following C# string

var myString= "Unfortunately there has been an error processing {0}'s order"

I want to pass that string into my React app and interpolate it in js but there does not seem to be a clean way of doing it

In my React app I want to do something like this

myString.format("John Doe")

So that I can get this output: "Unfortunately there has been an error processing John Does's order"

Some posts I've seen here suggested to create your own .format() method in js but I don't want to be reinventing the wheel if there are other solutions out there.

Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
jon v
  • 31
  • 1
  • 7
  • 1
    A format string and an interpolated string are different animals when in comes to usage. – Aluan Haddad May 07 '20 at 21:49
  • I've updated title to "format string" as body of the post does not show *interpolated* string - if that is wrong and you are looking for interpolated strings like `$"Bob had {applleCount + pearCount} fruits"` kind of formatting please [edit] to clarify (also that is covered in suggested duplicate too). Please note that looking for libraries (which may be another interpretation of the question) is off-topic on SO - saying that you don't like existing solutions (without even listing them) is not enough... – Alexei Levenkov May 07 '20 at 21:54

0 Answers0