c# split string in 2. letter by letter -
i need split string in 2, 1 letter each variable.
example: string = "abcdefghij" name1: acegi name2: bdfhj
i done far:
var builderm = new stringbuilder(); var builderk = new stringbuilder(); (int = 0; < s.length; i++) { builderm.append(s[i]); builderk.append(s[i++]); } txtm.text = builderm.tostring(); txtk.text = builderk.tostring();
but showing same text in 2.
you should use ++i
instead of i++
(int = 0; < s.length; i++) { builderm.append(s[i]); if(i + 1 < s.length) // prevent ior exception when count odd. builderk.append(s[++i]); // pre increment. }
the reason i++
post incremented. means i
gets incremented after expression therefor s[i++]
give same item s[i]
.
Comments
Post a Comment