c# - how to continues loop through string and return character of given index? -
string myinput = "abc"; int inputloopindex = 5;
now output should char output = b
i tried like
string myinput = "abc"; char mycharachter; (int = 0; <= inputloopindex ; i++) { mycharachter = myinput[i]; }
error - index out of bound
string myinput = "abc"; char mycharachter; (int = 0; <= 5; i++) { mycharachter = mystring[i % mystring.length]; }
you want use modulo (%
) operator, can used loop round (it gets remainder). read more on wikipedia.
Comments
Post a Comment