More REBOL/Power-Tools
[1/1] from: robbo1mark::aol::com at: 19-Feb-2001 15:38
MORE REBOL/Power-Tools
Here's some more REBOL/Power-Tools DE-SPACE & RE-SPACE
These functions remove & replace all whitespace characters
from a string! or file!
White-space is interchanged for Hex value just like
in a REBOL file path!
Very useful for PARSING purposes, enables string values to
remain intact whilst separating other values by whitespace.
Anyway here's the functions;
DE-SPACE: func [ "REPLACES ALL WHITE-SPACE CHARACTERS WITH A HEX
VALUE" target [ string! file!]] [ if (type? target) = file! [
target: read target] replace/all target " " " "]
RE-SPACE: func [ "REPLACES ALL HEX VALUES WITH WHITE-SPACE
CHARACTER" target [ string! file!]] [ if (type? target) = file! [
target: read target] replace/all target " " " "]
here's some examples;
>> a: de-space " this silly stupid string "
== { this silly stupid string }
>> a
== { this silly stupid string }
>> re-space a
== " this silly stupid string "
>> parse a none
== ["this" "silly" "stupid" "string"]
>> parse de-space a none
== [{ this silly stupid string }]
>> de-space %readme.txt
== {GUIcon (aka Console) Program for Win32 platforms,%
200.1.
3 (20-Jan-2001)
This is a readme file that e...
>> re-space de-space %readme.txt
== {GUIcon (aka Console) Program for Win32 platforms, 0.1.3 (20-Jan-
2001
)
This is a readme file that everyone should read first!
...
>>
; README.txt file courtesy of our GEO MASSAR
Here's a function that return an ASCII value or block of values
for a char! string! or file! { note file contents )
ASCII: func [ "RETURNS ASCII INTEGER VALUES" value [ char! string!
file! ]] [
if (type? value) = file! [value: read value]
if (type? value) = char! [ return to-integer value]
count: length? value
value-block: [] clear value-block
loop count [ append value-block to-integer pick value 1 value: next
value ]
return value-block
]
some examples;
>> ascii #"A"
== 65
>> ascii "A"
== [65]
>> ascii "APPLES"
== [65 80 80 76 69 83]
>> ascii %./guicon013/readme.txt
== [71 85 73 99 111 110 32 40 97 107 97 32 67 111 110 115 111 108 101
41
32 80 114 111 103 114 97 109 32 102 111 114 32 87 105 110 ...
>>
Feel free to add your own Power Tools & Functions.
still lots more to come,
PS -- Ralph Roberts, glad you liked my directory functions, thank you for
your kind words, it feels good to feel like I've done something good for a
change.
Sorry everybody for the big spat over the last few days, I don't like or want
religious wars in REBOL either!.
Mark Dickson