Easiest way to turn a substring into a string?

Sometimes I’m dealing with a function that only wants a String and not an AbstractString.

// this usually occurs if you use someone else’s code and you have a SubString


Is there a surefire way to convert a SubString to a String?

Related to:

String(x::SubString) does that, and you can broadcast String if helpful

4 Likes

This didn’t work. I just used this hack instead:

Foo.bar(string::AbstractString) = Foo.bar(String(string))

This is not a hack, but a very standard pattern, along the lines of

foo(x::SomeTypeICanDealWith) = ...

foo(x::SomeBroaderType) = foo(make_some_type_I_can_deal_with(x))
1 Like

How this different from what @JeffreySarnoff suggested?