Jump to content

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).
{{incorrect|J}}
 
* 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):
* String creation and destruction is not needed
<lang j> FIXMEname=: show mapped file example0</lang>
 
* StringExample binary string assignment
<lang j> name=: 'value'</lang>
 
* StringExample binary string comparison
<lang j> name1 -: name2</lang>
 
* StringExample binary string cloning and copying is not needed
<lang j> FIXME: show mapped filename1= 'example</lang>'
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
 
* CheckExample check if a binary string is empty
<lang j> 0=#string</lang>
 
* AppendExample apppend a byte to a binary string
<lang j> string,byte</lang>=: 'example'
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}}==
6,962

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.