Re: Splitting text up

new topic     » goto parent     » topic index » view thread      » older message » newer message

James W wrote:
> 
> 
> Hi i was woundering if it was possible to split some text up and then storing
> 
> them in differint variables
> 
> for example
> 
>         T  e  x  t
>         |  |  |  |
>         c1 c2 c3 c4
> 
> Thanks


Hi James

Euphoria's treatment of "strings" of text is quite nice as it is just a
flat sequence.

i.e.

text = "Text"               -- is equivalent to
text = {'T', 'e', 'x', 't'} -- nb this is a sequence of character _values_, ie
text = {84, 101, 120, 116}  -- same thing


Therefore
atom c1, c2, c3, c4
c1 = text[1]
c2 = text[2]
c3 = text[3]
c4 = text[4]


I don't know why you would want to do this though, as any results you get
you would surely want to store in a sequence, as in:

sequence vals

vals = {} -- important to initialise to empty sequence before using append()

for i = 1 to length(text) do
    vals = append(vals, text[i])
end for

-- the variable 'vals' is now identical to 'text'! smile


Far be it from me to guess why you asked the question though :) You would
want to do this more often for calculating values within the for loop.

Gary

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu