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

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -