Binary strings: Difference between revisions

add RPL
(→‎{{header|REXX}}: added output)
(add RPL)
Line 3,847:
See a + b + c
</syntaxhighlight>
=={{header|RPL}}==
Strings are a sequence of bytes.
String creation - no need for destruction as there is a garbage collection mechanism:
"This is a new string" <span style="color:grey">@ String is put at stack level 1</span>
String assignment:
"This is a string" '<span style="color:green">MYTEXT</span>' STO <span style="color:grey">@ String is transferred from stack level 1 to MYTEXT variable</span>
String comparison: numeric operators can be used for equality or lexicographic order
"This" "That" == <span style="color:grey">@ test equality - return 0 here</span>
"This" "That" > <span style="color:grey">@ test order - returns 1 here</span>
Inclusion can also be tested:
"This" "is" POS <span style="color:grey">@ returns position of substring - 3 here</span>
String cloning and copying: any object, including strings, can be duplicated in the stack:
"This" DUP <span style="color:grey">@ Put a copy of "This" at stack level #2</span>
Check if a string is empty:
<span style="color:green">MYTEXT</span> "" == <span style="color:grey">@ returns 1 if MYTEXT contains an empty string</span>
or
<span style="color:green">MYTEXT</span> SIZE NOT <span style="color:grey">@ returns 1 if MYTEXT contains an empty string</span>
Append a byte to a string:
"Thi" "s" +
Extract a substring from a string:
"This is a string" 2 4 SUB <span style="color:grey">@ returns substring from 2nd to 4th character</span>
Replace every occurrence of a byte (or a string) in a string with another string: we need a small program here, since the REPL function replaces only the first occurence of the searched substring
≪ → string old new <span style="color:grey">@ store arguments</span>
≪ string <span style="color:grey">@ put string to be replaced in stack</span>
'''WHILE''' DUP old POS '''REPEAT''' <span style="color:grey">@ while old is present in string</span>
LAST SWAP new REPL <span style="color:grey">@ replace old by new</span>
'''END'''
≫ ≫ '<span style="color:blue">REPLALL</span>' STO
Join strings:
"This is" " a string" +
 
=={{header|Ruby}}==
A String object holds and manipulates an arbitrary sequence of bytes. There are also the [http://www.ruby-doc.org/core/classes/Array.html#M002222 Array#pack] and [http://www.ruby-doc.org/core/classes/String.html#M000760 String#unpack] methods to convert data to binary strings.
Line 3,896 ⟶ 3,927:
c = "orld"
p d = a + b + c</syntaxhighlight>
 
=={{header|Run BASIC}}==
<syntaxhighlight lang="runbasic">' Create string
1,150

edits