Binary strings: Difference between revisions
J: clarification
(J: clarification) |
|||
Line 731:
=={{header|J}}==
J's literal data type supports arbitrary binary data (strings are binary strings by default). J's semantics are pass by value (with garbage collection) with a minor exception (mapped files).▼
* Example binary string creation
▲J's literal data type supports arbitrary binary data. J's semantics are pass by value (with garbage collection) with a minor exception (mapped files).
<lang j> name=: ''</lang>
* Example binary string deletion (removing all references to a string allows it to be deleted, in this case we give the name a numeric value to replace its prior string value):
<lang j>
*
<lang j> name=: 'value'</lang>
*
<lang j> name1 -: name2</lang>
*
<lang j>
name2= name1</lang>
Though, technically, its the internal reference which is cloned, not the internal representation of the value. But operations which modify strings are copy on write, so this distinction is not visible without going outside the language.
* Check if a string is empty▼
<lang j> 0=#string</lang>
*
<lang j> string
byte=: DEL
string=: string,byte</lang>
* Extract a substring from a binary string
<lang j> 3{.5}.'The quick brown fox runs...'</lang>
Line 762 ⟶ 768:
* Join strings
<lang j> 'string1','string2'</lang>
Note also: given an integer n, the corresponding byte value may be obtained by indexing into <code>a.</code> which is the ordered array of all bytes.:
<lang j> n{a.</lang>
Thus, the binary string containing bytes with numeric values 1 0 255 can be obtained this way:
<lang j>1 0 255{a.</lang>
=={{header|Lua}}==
|