Definition: | string res = to_string(object data_in, integer string_quote=0, integer embed_string_quote='"') |
Description: |
Converts an object into a text string.
data_in: Any phix object. string_quote: If not zero (the default) this is used to enclose data_in, if it is already a string. embed_string_quote: Used to enclose any strings embedded inside data_in. The default is double quote. Returns the string repesentation of data_in. |
Comments: |
The returned value is guaranteed to be a displayable text string.
string_quote is only used if data_in is already a string. In this case, if string_quote is zero the string is returned unaltered, otherwise all occurances of string_quote already in data_in are prefixed with the ’\’ escape character, as are any pre-existing escape characters. Then string_quote is added to both ends of data_in, resulting in a quoted string. embed_string_quote is only used if data_in is a sequence that contains strings. In this case, it is used as the enclosing quote for embedded strings. This routine is defined in builtins/to_str.e (an autoinclude) and is provided only for compatibility with OpenEuphoria. |
Example: |
procedure display(string s) puts(1,s) puts(1,"\n") end procedure display(to_string(12)) -- 12 display(to_string("abc")) -- abc display(to_string("abc",'"')) -- "abc" display(to_string(`abc\"`,'"')) -- "abc\\\"" display(to_string({12,"abc",{4.5, -99}})) -- {12, "abc", {4.5, -99}} display(to_string({12,"abc",{4.5, -99}},0,0)) -- {12, abc, {4.5, -99}} |