Re: Question about print,puts,get,gets,...
- Posted by martin.stachon at worldonline.cz Jun 13, 2001
- 368 views
----- Original Message ----- From: <david at aldred.demon.co.uk> Subject: Re: Question about print,puts,get,gets,... > >2.Get it from control and put it to file.dat as part of sequence. > > {"Tim","Mary","David",...} > > > Then you need to put MyString into a sequence. If you have three of > them, you can do this simply by saying: > > seq = {MyString1, MyString2, MyString3} > > >If I look file.dat I wish to see it as writen above. > > Actually, you won't. You'll see it written in a series of character > codes separated by commas and braces. If you really want it legible > outside Euphoria, you'll probably need to use > > printf (fn,"{\"%s\",\"%s,\",\"%s\"}", > {MyString1,MyString2,MyString3}) You can use this code : include misc.e type string(sequence s) for i=1 to length(s) do if not atom(s[i]) then return 0 end if end for return 1 end type global function string_print(object x) sequence s if atom(x) then return sprintf("%.10g", x) elsif string(x) then return '"' & x & '"' else s = "{" for i = 1 to length(x) do s &= string_print(x[i]) if i < length(x) then s &= ',' end if end for s &= "}" return s end if end function sequence test test = {"Hello", "World", { "Nested", "seqeunce" } ,1,2,3 , {1,2,3}} puts(1,string_print(test)) However, the code cannot recognize if some sequence could be a string {1,2,3} but you don't want it to be printed as string, because there is no difference between strings and sequences in EU. Regards, Martin