Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a string like this: 1,b,1,28,2,g,9,95,3,y,4,60,4,r,4,8,5,b,10,46,6,b,10,45,7,g,8,94,8,r,8,16,9,y,3,58,15,r,10,20,16,g,5,87,19,r,1,2,21,y,1,54,22,b,3,31,1,r,9,17

I want to split this every fourth time I hit a comma and afterwards count how many times it has been split, but I have no idea how to do so :-/

I came across this, but it is JavaScript and I want to be able to do this in C#:

var j:int = 0;
var h:String;
for(var thisvalue:String in thestring){
    h += (j%4 == 3)?thisvalue+';':thisvalue+','; 
    j++;
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.4k views
Welcome To Ask or Share your Answers For Others

1 Answer

var cnt = (thestring.Count(x => x == ',') + 1) / 4;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...