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

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -