c# - Remove text after a string occurrence -
i have string has following format:
string sample = "a, abc, 1, acs,,"
as can see, there 5 occurences of ,
character. need remove everything after 4th occurrence final result be:
string result = fx(sample, 4); "a, abc, 1, acs"
is possible without foreach
? in advance.
you this:
sample.split(',').take(4).aggregate((s1, s2) => s1 + "," + s2).substring(1);
this split string @ comma , take first 4 parts ("a"
, " abc"
, " 1"
, " acs"
), concat them 1 string aggregate
(result: ",a, abc, 1, acs"
) , return except first character. result: "a, abc, 1, acs"
.
Comments
Post a Comment