This comment is reply for 4235 にしお: 正規表現を使いました。 count...(文字列の均等分割). Go to thread root.
naranja #5320(2008/01/14 12:43 GMT) [ D ] Rating0/0=0.00
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
import std.stdio; import std.regexp; import std.string; string[] divid(uint n, string s){ string[] ret; for(uint i;; i++){ auto pat = "^" ~ format("(.{%d,%d})", i, i + 1).repeat(n) ~ "$"; if(auto m = search(s, pat)){ for(uint j = 1; j <= n; j++){ ret ~= m.match(j); // ret ~= m[j]; } break; } } return ret; } void main(){ auto sample = "ゆめよりもはかなき世のなかをなげきわびつゝあかしくらすほどに四月十よひにもなりぬれば木のしたくらがりもてゆく"; writefln(divid(4, sample).join("\n")); writefln("----"); writefln(divid(5, sample).join("\n")); writefln("----"); writefln(divid(6, sample).join("\n")); }
Rating0/0=0.00-0+
[ reply ]
naranja
#5320()
[
D
]
Rating0/0=0.00
Rating0/0=0.00-0+