Binary strings: Difference between revisions

m
(Replace println() with print(); replace output "syntaxhighlight" tag with "pre" tag)
Line 1,114:
=={{header|Ecstasy}}==
<syntaxhighlight lang="java">
module BinaryStrings {
{
@Inject Console console;
void run() {
{
Byte[] mutableBytes = new Byte[]; // growable and mutable string of bytes
Byte[] fixedLength = new Byte[10]; // fixed length string of bytes (all default to 0)
Line 1,136 ⟶ 1,134:
);
 
mutableBytes += 0; // add a byte (using an operator)
mutableBytes.add(1); // add a byte (using the underlying method)
mutableBytes.addAll(#07FF); // add multiple bytes (using the underlying method)
console.print($|Append a byte to a string:
| mutableBytes={mutableBytes}
Line 1,151 ⟶ 1,149:
 
fixedLength = new Byte[4](i -> literal[i]); // create/copy from literal to fixedLength
val clone = fixedLength.cloneduplicate(); // clone the array
console.print($|String cloning and copying:
| fixedLength={fixedLength}
Line 1,165 ⟶ 1,163:
);
 
for (Int start = 0; Int index := fixedLength.indexOf(0x01, start); start = index) {
{
fixedLength[index] = 0x04;
}
console.print($|Replace every occurrence of a byte in a string with another string:
| fixedLength={fixedLength}
Line 1,174 ⟶ 1,171:
);
 
for (Int start = 0; Int index := mutableBytes.indexOf(#0107, start); start = index) {
{
mutableBytes.replaceAll(index, #9876);
}
console.print($|Replace every occurrence of a string in a string with another string:
| mutableBytes={mutableBytes}
Line 1,187 ⟶ 1,183:
|
);
}
}
}
</syntaxhighlight>
 
162

edits