how to add 0 to a string

View: New views
3 Messages — Rating Filter:   Alert me  

how to add 0 to a string

by kimm furt-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

hi,

i'm still trying to send an xml-style sting via tcp to another app...
ie: NetAddr("bla",12345).sendRaw("<xlmString />")
to terminate the sting it has to be ended with a binary 0. 
but somehow sc seems to ignore all 0s:

("some string" ++ 0.asAscii).ascii returns
[ 115, 111, 109, 101, 32, 115, 116, 114, 105, 110, 103 ]
("some string" ++ 54.asAscii).ascii returns
[ 115, 111, 109, 101, 32, 115, 116, 114, 105, 110, 103, 54 ]
("some string" ++ 0).ascii gives me the 0's ascii value
[ 115, 111, 109, 101, 32, 115, 116, 114, 105, 110, 103, 48 ]

is there any way to add the binary zero, and use it with NetAddr.sendRaw?
or is it possible to use integers as ascii-values and change them back into
a string (the opposite of .asAscii).

thanks,
florian


Re: how to add 0 to a string

by Scott Wilson-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Something like this:

("some string".ascii ++ 0).collectAs(_.asAscii, String).ascii
[ 115, 111, 109, 101, 32, 115, 116, 114, 105, 110, 103, 0 ]

S.

On 22 Apr 2009, at 14:41, kimm furt wrote:

hi,

i'm still trying to send an xml-style sting via tcp to another app...
ie: NetAddr("bla",12345).sendRaw("<xlmString />")
to terminate the sting it has to be ended with a binary 0. 
but somehow sc seems to ignore all 0s:

("some string" ++ 0.asAscii).ascii returns
[ 115, 111, 109, 101, 32, 115, 116, 114, 105, 110, 103 ]
("some string" ++ 54.asAscii).ascii returns
[ 115, 111, 109, 101, 32, 115, 116, 114, 105, 110, 103, 54 ]
("some string" ++ 0).ascii gives me the 0's ascii value
[ 115, 111, 109, 101, 32, 115, 116, 114, 105, 110, 103, 48 ]

is there any way to add the binary zero, and use it with NetAddr.sendRaw?
or is it possible to use integers as ascii-values and change them back into
a string (the opposite of .asAscii).

thanks,
florian



Re: how to add 0 to a string

by kimm furt-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

wow, thanks!
it works...

Am 22.04.2009 um 15:48 schrieb Scott Wilson:

Something like this:

("some string".ascii ++ 0).collectAs(_.asAscii, String).ascii
[ 115, 111, 109, 101, 32, 115, 116, 114, 105, 110, 103, 0 ]

S.

On 22 Apr 2009, at 14:41, kimm furt wrote:

hi,

i'm still trying to send an xml-style sting via tcp to another app...
ie: NetAddr("bla",12345).sendRaw("<xlmString />")
to terminate the sting it has to be ended with a binary 0. 
but somehow sc seems to ignore all 0s:

("some string" ++ 0.asAscii).ascii returns
[ 115, 111, 109, 101, 32, 115, 116, 114, 105, 110, 103 ]
("some string" ++ 54.asAscii).ascii returns
[ 115, 111, 109, 101, 32, 115, 116, 114, 105, 110, 103, 54 ]
("some string" ++ 0).ascii gives me the 0's ascii value
[ 115, 111, 109, 101, 32, 115, 116, 114, 105, 110, 103, 48 ]

is there any way to add the binary zero, and use it with NetAddr.sendRaw?
or is it possible to use integers as ascii-values and change them back into
a string (the opposite of .asAscii).

thanks,
florian