probably a trivial question...
Ali Çehreli
acehreli at yahoo.com
Fri Oct 14 00:32:14 UTC 2022
Changing the order of lines...
On 10/13/22 16:43, WhatMeWorry wrote:
> return s.split(';'); // single quotes
That one is a single character and very lightweigth because it's just an
integral value. You can't put more than one character within single quotes:
';x' // ERROR
> return s.split(";"); // double quotes
That one is a string, which is the equivalent of the following "fat
pointer":
struct Array_ {
size_t length;
char * ptr;
}
For that reason, it can be seen as a little bit more costly. 'length'
happens to be 1 but you can use multiple characters in a string:
";x" // works
(Aside: There is also a '\0' character sitting next to the ';' in memory
so that the literal can be passed to C functions as-is.)
Double-quoted strings have the property of escaping. For example, "\n"
is not 2 characters but is "the newline character".
> return s.split(`;`); // back ticks
They are strings as well but they don't do escaping: `\n` happens to be
2 characters.
There is also strings that start with q{ and end with }:
auto myString = q{
hello
world
};
And then there is delimited strings that use any delimiter you choose:
auto myString = q"MY_DELIMITER
hello
world
MY_DELIMITER";
Some information here:
http://ddili.org/ders/d.en/literals.html#ix_literals.string%20literal
Ali
More information about the Digitalmars-d-learn
mailing list