Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -1,45 +1,45 @@
|
|||
import std.array: empty;
|
||||
import std.string: replace;
|
||||
void main() /*@safe*/ {
|
||||
import std.array: empty, replace;
|
||||
import std.string: representation, assumeUTF;
|
||||
|
||||
void main() {
|
||||
// String creation (destruction is usually handled by
|
||||
// the garbage collector)
|
||||
// the garbage collector).
|
||||
ubyte[] str1;
|
||||
|
||||
// String assignments
|
||||
str1 = cast(ubyte[])"blah";
|
||||
// hex string, same as "\x00\xFB\xCD\x32\xFD\x0A"
|
||||
// whitespace and newlines are ignored
|
||||
// String assignments.
|
||||
str1 = "blah".dup.representation;
|
||||
// Hex string, same as "\x00\xFB\xCD\x32\xFD\x0A"
|
||||
// whitespace and newlines are ignored.
|
||||
str1 = cast(ubyte[])x"00 FBCD 32FD 0A";
|
||||
|
||||
// String comparison
|
||||
// String comparison.
|
||||
ubyte[] str2;
|
||||
if (str1 == str2) {} // strings equal
|
||||
if (str1 == str2) {} // Strings equal.
|
||||
|
||||
// String cloning and copying
|
||||
str2 = str1.dup; // copy entire string or array
|
||||
// String cloning and copying.
|
||||
str2 = str1.dup; // Copy entire string or array.
|
||||
|
||||
// Check if a string is empty
|
||||
if (str1.empty) {} // string empty
|
||||
if (str1.length) {} // string not empty
|
||||
if (!str1.length) {} // string empty
|
||||
if (str1.empty) {} // String empty.
|
||||
if (str1.length) {} // String not empty.
|
||||
if (!str1.length) {} // String empty.
|
||||
|
||||
// Append a ubyte to a string
|
||||
// Append a ubyte to a string.
|
||||
str1 ~= x"0A";
|
||||
str1 ~= 'a';
|
||||
|
||||
// Extract a substring from a string
|
||||
str1 = cast(ubyte[])"blork";
|
||||
// this takes off the first and last bytes and
|
||||
// assigns them to the new ubyte string
|
||||
// This is just a light slice, no string data copied
|
||||
ubyte[] substr = str1[1 .. $-1];
|
||||
// Extract a substring from a string.
|
||||
str1 = "blork".dup.representation;
|
||||
// This takes off the first and last bytes and
|
||||
// assigns them to the new ubyte string.
|
||||
// This is just a light slice, no string data copied.
|
||||
ubyte[] substr = str1[1 .. $ - 1];
|
||||
|
||||
// Replace every occurrence of a ubyte (or a string)
|
||||
// in a string with another string
|
||||
str1 = cast(ubyte[])"blah";
|
||||
replace(cast(char[])str1, "la", "al");
|
||||
// in a string with another string.
|
||||
str1 = "blah".dup.representation;
|
||||
replace(str1.assumeUTF, "la", "al");
|
||||
|
||||
// Join strings
|
||||
// Join two strings.
|
||||
ubyte[] str3 = str1 ~ str2;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue