Binary strings: Difference between revisions
Content added Content deleted
(J: clarification) |
|||
Line 731: | Line 731: | ||
=={{header|J}}== |
=={{header|J}}== |
||
⚫ | |||
{{incorrect|J}} |
|||
* Example binary string creation |
|||
⚫ | |||
<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> |
<lang j> name=: 0</lang> |
||
* |
* Example binary string assignment |
||
<lang j> name=: 'value'</lang> |
<lang j> name=: 'value'</lang> |
||
* |
* Example binary string comparison |
||
<lang j> name1 -: name2</lang> |
<lang j> name1 -: name2</lang> |
||
* |
* Example binary string cloning and copying |
||
<lang j> |
<lang j> name1= 'example' |
||
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. |
|||
⚫ | |||
⚫ | |||
<lang j> 0=#string</lang> |
<lang j> 0=#string</lang> |
||
* |
* Example apppend a byte to a binary string |
||
<lang j> string |
<lang j> string=: 'example' |
||
byte=: DEL |
|||
string=: string,byte</lang> |
|||
* Extract a substring from a string |
* Extract a substring from a binary string |
||
<lang j> 3{.5}.'The quick brown fox runs...'</lang> |
<lang j> 3{.5}.'The quick brown fox runs...'</lang> |
||
Line 762: | Line 768: | ||
* Join strings |
* Join strings |
||
<lang j> 'string1','string2'</lang> |
<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}}== |
=={{header|Lua}}== |