1. int2str.e
- Posted by Arthur Adamson <euclid at ISOC.NET> Oct 25, 1997
- 689 views
- Last edited Oct 26, 1997
I needed to convert an integer to a string for using it in a file name for instance. I overlooked it someplace imagine but I couldn't find any built in function to do so. I wrote the following which handles the problem...but tell me, is there a built in way? Thanks, Art Adamson --convert an int to a string global function intToStr(integer tempInt) sequence seqOut seqOut = {} while floor(tempInt) do seqOut = prepend(seqOut, 48 + remainder(tempInt,10)) tempInt = floor(tempInt / 10) end while return seqOut end function --intToStr --puts(1,"The sequence returned is: ") --? intToStr(1234) --puts(1,intToStr(1234)) Arthur P. Adamson, The Cincinnati Engine Man, euclid at isoc.net
2. Re: int2str.e
- Posted by Pete Eberlein <xseal at HARBORSIDE.COM> Oct 25, 1997
- 681 views
Arthur Adamson wrote: > I needed to convert an integer to a string for using it in a file > name for instance. I overlooked it someplace imagine but I couldn't find any > built in function to do so. I wrote the following which handles the > problem...but tell me, is there a built in way? Thanks, Art Adamson > > --convert an int to a string > global function intToStr(integer tempInt) > sequence seqOut > seqOut = {} > while floor(tempInt) do > seqOut = prepend(seqOut, 48 + remainder(tempInt,10)) > tempInt = floor(tempInt / 10) > end while > return seqOut > end function --intToStr > > --puts(1,"The sequence returned is: ") > --? intToStr(1234) > --puts(1,intToStr(1234)) > Arthur P. Adamson, The Cincinnati Engine Man, euclid at isoc.net Did you try sprintf? --puts(1,"The sequence returned is: ") --? sprintf("%d",{1234}) --puts(1,sprintf("%d",{1234})) It does hex and floating point too. -- _____ _____ _____ ________ /\ \ /\ \ /\ \ / \ \ / \____\ / \____\ / \____\ / _ \____\ / / ___/_ / /____/ / / ___/_ / / \ [___] / / /\____\ / \ \ / / /\____\ \ \_/ / / \ \/ / ___/_\ \ \ \ \/ / ___/_ \ /____/ \ / /\ \\/\ \ \ \ / /\ \ \ \ \ \ \/ \____\ \ \ \ \ \/ \____\ \ \ \ \ / / \ \____\ \ / / \ \____\ \ / / \ / / \ / / \ / / \ / / \/____/ \ / / \/____/ \/____/xseal at harborside.com\/____/
3. int2str.e
- Posted by Bryan Watts <mr_bungle at COMPUSERVE.COM> Oct 25, 1997
- 676 views
- Last edited Oct 26, 1997
Aruthur Adamson wrote: > I needed to convert an integer to a string for using it in a file >name for instance. I overlooked it someplace imagine but I couldn't find= any >built in function to do so. I wrote the following which handles the >problem...but tell me, is there a built in way? Thanks, Art Adamson > >--convert an int to a string >global function intToStr(integer tempInt) >sequence seqOut >seqOut =3D {} >while floor(tempInt) do > seqOut =3D prepend(seqOut, 48 + remainder(tempInt,10)) > tempInt =3D floor(tempInt / 10) >end while >return seqOut >end function --intToStr >--puts(1,"The sequence returned is: ") >--? intToStr(1234) >--puts(1,intToStr(1234)) >Arthur P. Adamson, The Cincinnati Engine Man, euclid at isoc.net Actually Arthur, there is a function call "sprintf" that will accomplish this for you. The syntax is: s =3D sprintf(st,x) where st is a format string, and x is the number. It is used like this: integer num sequence s num =3D 15 s =3D sprintf("%03d",num) -- s comes out to be "015" I hope this helps. If you need further assistance, check the library routines in the included documentation. Regards, Bryan Watts
4. Re: int2str.e
- Posted by Pete Eberlein <xseal at HARBORSIDE.COM> Oct 26, 1997
- 675 views
Daniel Berstein wrote: > > On 25 Oct 97 , Pete Eberlein wrote: > > > Did you try sprintf? > > > > --puts(1,"The sequence returned is: ") > > --? sprintf("%d",{1234}) > > --puts(1,sprintf("%d",{1234})) > > > > It does hex and floating point too. > > But how do you store that string in a variable (sequence) for further > use? Um, I haven't tested this, but you might be able to use the assignment operator: sequence s s = sprintf("%d",{1234}) puts(1,"The sequence returned is: ") ? s puts(1, s) The sprintf function returns a sequence formatted the same way as the printf procedure. The following two lines are equivalent: printf(1, "%d\n", {1234}) puts(1, sprintf("%d\n", {1234})) -- _____ _____ _____ ________ /\ \ /\ \ /\ \ / \ \ / \____\ / \____\ / \____\ / _ \____\ / / ___/_ / /____/ / / ___/_ / / \ [___] / / /\____\ / \ \ / / /\____\ \ \_/ / / \ \/ / ___/_\ \ \ \ \/ / ___/_ \ /____/ \ / /\ \\/\ \ \ \ / /\ \ \ \ \ \ \/ \____\ \ \ \ \ \/ \____\ \ \ \ \ / / \ \____\ \ / / \ \____\ \ / / \ / / \ / / \ / / \ / / \/____/ \ / / \/____/ \/____/xseal at harborside.com\/____/
5. Re: int2str.e
- Posted by Arthur Adamson <euclid at ISOC.NET> Oct 26, 1997
- 682 views
Thanks to Pete Eberlein and others for solving my problem. Sorry I overlooked the solution. Bye, Art ---------------------------------------------------- >Arthur Adamson wrote: >> I needed to convert an integer to a string for using it in a file Arthur P. Adamson, The Cincinnati Engine Man, euclid at isoc.net