sprint
Definition: | string s = sprint(object x, integer asCh=false, maxlen=-1[, nest=0]) |
Description: |
The representation of x as a string of characters is returned. This is exactly the same as print(fn, x[, asCh[, maxlen]]), except that the output is returned as a string, rather than being sent to a file or device. x: can be any phix object. asCh: true: print eg 65 as 65'A', false: not top-level, -1: sticky false. maxlen: (desktop only) the maximum desired length in characters of the returned result. Anything beyond this is indicated by a trailing "..", potentially in addition to the specified length. See the Technicalia drop-down below for more details and the nest parameter. Most calls would probably only provide the first and maybe second parameter. |
pwa/p2js: | Supported. No maxlen or nest parameters (as yet, see below). |
Comments: |
The atoms contained within x will be displayed to a maximum of 10 significant digits, just as with print().
An asCh of false means that sprint(65) yields "65" whereas sprint({65,66,67}) yields "{65'A',66'B',67'C'}" and the same for %v in (s)printf() and the ? shorthand. The %V format specifies a -1 for asCh. The presence of the string type makes asCh=true handling less necessary (than Eu) in Phix, except for debugging, where eg {97'a',98'b',"c"} may make it easier for you to realise your mistake than {97,98,"c"} would, or indeed spot such a value as being erroneous in the first place. |
Examples: |
s = sprint(12345) -- s is "12345" s = sprint({1,2.5,"hello",{4,5.5}}) -- s is `{1,2.5,"hello",{4,5.5}}` s = sprint("hello") -- s is `"hello"` s = sprint("hello"&-1) -- s is `{104'h',101'e',108'l',108'l',111'o',-1}` s = sprint("hello"&-1,-1) -- s is `{104,101,108,108,111,-1}` |
Implementation: | See builtins\VM\pprntfN.e (an autoinclude) for details of the actual implementation. (Moved/merged from psprintN.e in 0.8.2) |
See Also: | print, sprintf, value, get |
