Anonymous user
Binary strings: Difference between revisions
Forth (all strings are binary)
(+Icon+Unicon) |
(Forth (all strings are binary)) |
||
Line 515:
<lang factor>B{ 147 250 150 123 } shift-jis decode .</lang>
<pre>"日本"</pre>
=={{header|Forth}}==
Counted strings are often used to store a string in memory.
<lang forth>create cstr1 ," A sample string"
create cstr2 ," another string"
create buf 256 allot
cstr1 count buf place
s" and " buf +place
cstr2 count buf +place
buf count type \ A sample string and another string</lang>
All strings are binary strings, represented with a base address and a byte count. Most string functions operate on these address-length pairs.
Built-in string/memory functions:
* COMPARE compares two strings
* MOVE copies a string to another location
* CMOVE and CMOVE> can copy chunks of bytes around within a string, either down or up.
Substrings are represented by a different pointer and count within a string.
Other functions may be defined.
<lang forth>: empty? ( str len -- ? ) nip 0= ;
: +c ( c str len -- ) + c! ;
: replace-bytes ( from to str len -- )
bounds do
over i c@ = if dup i c! then
loop 2drop ;
</lang>
=={{header|Haskell}}==
|