Using Julia, I'd like to reliably convert any type into type String. There seems to be two ways to do the conversion in v0.5, either the string function or String constructor. The problem is that you need to choose the right one depending upon the input type.
For example, typeof(string(1)) evaluates to String, but String(1) throws an error. On the other hand, typeof(string(SubString{String}("a"))) evaluates to Substring{String}, which is not a subtype of String. We instead need to do String(SubString{String}("a")).
So it seems the only reliable way to convert any input x to type String is via the construct:
String(string(x))
which feels a bit cumbersome.
Am I missing something here?
Stringat the exclusion of all otherAbstractStrings? Ideally you shouldn't need to care about the exact string type. - mbaumanAbstractStringin my type definitions... :-) For the sake of completeness, does this mean that theString(string(x))is the most reliable way of getting aStringtype? - Colin T Bowersstring(::SubString)returns aString. - Bogumił Kamiński