Rebol Talk Forum  |  Getting Started  |  Newbie Help  |  Topic: convert a string into ascii decimal values
Pages: [1] Print
Author Topic: convert a string into ascii decimal values  (Read 727 times)
leke
Jr. Member
**
Offline Offline

Posts: 92


View Profile WWW
convert a string into ascii decimal values
« on: October 08, 2006, 11:17:57 AM »

Can anyone show me how to convert a string into ascii decimal values?
Logged

PeterWood
Newbie
*
Offline Offline

Posts: 34


View Profile
Re: convert a string into ascii decimal values
« Reply #1 on: October 08, 2006, 06:55:15 PM »

>> str: "ABCDE"
== "ABCDE"
>> probe to binary! str
#{4142434445}
== #{4142434445}

or

>> probe to-binary str
#{4142434445}

Two good places to look for hints about rebol are:

The Rebol Dictionary - http://www.rebol.com/docs/dictionary.html

The Rebol Mailing List Archive - http://www.rebol.org/cgi-bin/cgiwrap/rebol/ml-topic-index.r
Logged
leke
Jr. Member
**
Offline Offline

Posts: 92


View Profile WWW
Re: convert a string into ascii decimal values
« Reply #2 on: October 09, 2006, 02:51:23 AM »

Thanks, all those ascii values are bunched up though.

If I try my parse powers to separate them (including the white space)
Code:
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"
== ["" "" " " "" " " "" ""]
Code:
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
Full Member
***
Offline Offline

Posts: 182


View Profile WWW
Re: convert a string into ascii decimal values
« Reply #3 on: October 09, 2006, 03:51:45 AM »

There are many ways you can do that.

Code:
>> 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
Newbie
*
Offline Offline

Posts: 17


View Profile
Re: convert a string into ascii decimal values
« Reply #4 on: October 10, 2006, 07:34:34 AM »

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
Newbie
*
Offline Offline

Posts: 17


View Profile
Re: convert a string into ascii decimal values
« Reply #5 on: October 10, 2006, 07:40:08 AM »

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
leke
Jr. Member
**
Offline Offline

Posts: 92


View Profile WWW
Re: convert a string into ascii decimal values
« Reply #6 on: October 11, 2006, 06:33:45 AM »

Cool  Kiss
Logged

Pages: [1] Print 
Rebol Talk Forum  |  Getting Started  |  Newbie Help  |  Topic: convert a string into ascii decimal values
Jump to:  

  
Quick Search...

Advanced search
  
Welcome, Guest. Please login or register.
Did you miss your activation email?
December 02, 2008, 07:08:47 AM
Username: Password: Session Length:
  

News: 01-09-08

Alpha version of REBOL 3 has been released!


  
2311 Posts in 595 Topics by 4139 Members
Latest Member: DietaVato

  Rebol Talk Forum | Powered by SMF 1.0.9.
© 2001-2005, Lewis Media. All Rights Reserved.

RT design by Defiant Pc