Extract sub string from a string
Ali Çehreli
acehreli at yahoo.com
Mon Nov 9 18:55:44 UTC 2020
On 11/9/20 9:53 AM, k2aj wrote:
> string text = "welcome2worldinfo";
> string hg = toUpper(text[0..7] ~ "-" ~ text[7..8] ~ "-" ~ text[8..13]);
If those concatenations with the ~ operators prove to be costly at
runtime, the following range expression may be faster because it does
not allocate any memory:
import std.string;
import std.range;
import std.algorithm;
import std.stdio;
void main() {
string text = "welcome2worldinfo";
auto hg = chain(text[0..7], only('-'), text[7..8], only('-'),
text[8..13]).map!toUpper;
writeln(hg);
}
Ali
More information about the Digitalmars-d-learn
mailing list