|
Pages: [1]
|
 |
|
Author
|
Topic: convert a string into ascii decimal values (Read 731 times)
|
|
leke
|
Can anyone show me how to convert a string into ascii decimal values?
|
|
|
|
|
Logged
|
|
|
|
|
|
|
leke
|
Thanks, all those ascii values are bunched up though. If I try my parse powers to separate them (including the white space) x: "ab cd efg" >> parse/all/case x none == ["ab cd efg"] >> parse/all/case x "" == ["ab cd efg"] >> parse/all/case x " " == ["ab" "cd" "efg"] >> parse/all/case x "abcdefg" == ["" "" " " "" " " "" ""] Just can't seem to figure out how to parse it like this, == ["a" "b" " " "c" "d" " " "e" "f" "g"] What's the magic word I need to stick at the end of the parse spell? Sorry, I did do a search for REBOL scripts with ASCII, but nothing came up. I realise now that it would be part of the binary word (ascii is 8 bit binary right?).
|
|
|
|
|
Logged
|
|
|
|
|
Gabriele
|
There are many ways you can do that. >> str: "ABCD" == "ABCD" >> str/1 == #"A" >> to integer! str/1 == 65 >> bin: as-binary str == #{41424344} >> bin/1 == 65 >> foreach char bin [print char] 65 66 67 68
|
|
|
|
|
Logged
|
|
|
|
|
rebolek
|
If you want to use parse:
>> x: "ab cd efg" == "ab cd efg" >> out: copy [] == [] >> parse/all/case x [any [z: char! skip (append out to integer! z/1)]] == true >> out == [97 98 32 99 100 32 101 102 103] >>
|
|
|
|
|
Logged
|
|
|
|
|
rebolek
|
BTW, ASCII is 7bit, extended codepages are 8bit. But the difference between string and binary in REBOL is in new-lines handling (string converts new lines according to platform, binary preserves file as-is).
|
|
|
|
|
Logged
|
|
|
|
|
|
|
|
Pages: [1]
|
|
|
 |
News: 01-09-08 Alpha version of REBOL 3 has been released!
2311 Posts in 595 Topics by 4145 Members
Latest Member: Domiadito
|