Please specify what version of Turing you are using
4.1.1
Sponsor Sponsor
chrisbrown
Posted: Wed Jun 02, 2010 12:14 pm Post subject: RE:Array to string
Although you can't "put" an array, you can use a for loop to output each character sequentially, or you can append each character to a string:
Turing:
var s :string:=""% must be initialized var c :char
c :=getchar% say user inputs 'x'
s += c
put s % outputs: x
c :=getchar% user inputs y
s += c
put s % outputs: xy
supaphreek
Posted: Wed Jun 02, 2010 1:44 pm Post subject: RE:Array to string
Well, im trying to make it as a username... so i need the array to be 1 word in a string. how would i do that?
Thx alot tho, i relle appreciate ur help!
chrisbrown
Posted: Wed Jun 02, 2010 1:53 pm Post subject: Re: RE:Array to string
supaphreek @ Wed Jun 02, 2010 1:44 pm wrote:
i need the array to be 1 word in a string.
I'm not sure what you mean... do you want each element in the array to contain one character? Or each element to contain one username?
supaphreek
Posted: Wed Jun 02, 2010 2:05 pm Post subject: RE:Array to string
well, i need to be able to put everything in the array into 1 string....
chrisbrown
Posted: Wed Jun 02, 2010 2:51 pm Post subject: RE:Array to string
Ah ok. Unless it's a requirement, you dont need the array at all, you can just append to a string using the technique in the code i provided.
If it is required, my example will still help. After all characters have been read into the array, append each character to a string using a for loop.
Again, if required: Turing will make the conversion for you but you should change c to an array of char instead of string for clarity's sake.