countUntil to print all the index of a given string.
Vino
vino.bheeman at hotmail.com
Sun Feb 18 11:55:37 UTC 2018
Hi All,
Request your help on printing the all index of an array element
, eg; the below code prints the index of the string "Test2" as
[1], but the string "Test2" is present 2 times at index 1 and
4, so how do I print all the index of a given string.
import std.stdio;
import std.container;
import std.algorithm;
void main () {
auto a = Array!string("Test1", "Test2", "Test3", "Test1",
"Test2");
writeln(SList!int(a[].countUntil("Test2"))[]);
}
Output
[1]
Expected
[1, 4]
From,
Vino.B
More information about the Digitalmars-d-learn
mailing list