[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

beginner question conversion array <-> string

kiksen1

1/11/2005 1:12:00 PM

hello all,

I am trying to convert a string (s="-----boundary with some http
stuff") to an arry to pass it to http::post as data. I need every
character in as an extra element (like aX = ["-","-","b","o"....]

I played with unpack(which looks like a good way) but no success.

My last try was this loop but the characters are safed as figures and
not as characters any more.

s.each_byte do |x|
aX << x
end

Thanks a lot!
best
Christian
3 Answers

Sea&Gull

1/11/2005 1:23:00 PM

0

Christian Knoblauch wrote:
> hello all,
>
> I am trying to convert a string (s="-----boundary with some http
> stuff") to an arry to pass it to http::post as data. I need every
> character in as an extra element (like aX = ["-","-","b","o"....]
>
> I played with unpack(which looks like a good way) but no success.
>
> My last try was this loop but the characters are safed as figures and
> not as characters any more.
>
> s.each_byte do |x|
> aX << x
> end
>

s.each_byte do |x|
aX << x.chr
end

James Britt

1/11/2005 1:35:00 PM

0

Christian Knoblauch wrote:
> hello all,
>
> I am trying to convert a string (s="-----boundary with some http
> stuff") to an arry to pass it to http::post as data. I need every
> character in as an extra element (like aX = ["-","-","b","o"....]
>
> I played with unpack(which looks like a good way) but no success.
>
> My last try was this loop but the characters are safed as figures and
> not as characters any more.
>
> s.each_byte do |x|
> aX << x
> end
try

s.split( // )



Curne) Simon Conrad-Armes

1/11/2005 1:36:00 PM

0


On 2005 Jan, 11, at 14:16, Christian Knoblauch wrote:

> hello all,
>
> I am trying to convert a string (s="-----boundary with some http
> stuff") to an arry to pass it to http::post as data. I need every
> character in as an extra element (like aX = ["-","-","b","o"....]

the easy way is #split

---------
"abc".split('') # => [ "a", "b", "c" ]
---------

Can't you just write the string to the HTTP thingy, though?

//Curne

>
> I played with unpack(which looks like a good way) but no success.
>
> My last try was this loop but the characters are safed as figures and
> not as characters any more.
>
> s.each_byte do |x|
> aX << x
> end
>
> Thanks a lot!
> best
> Christian
>
>