[Solved] C# get position of a character from string


string aS = "ABCDEFGHI";
char ch="C";
int idx = aS.IndexOf(ch);
MessageBox.Show(string.Format("{0} is in position {1} and between {2} and {3}", ch.ToString(), idx + 1, aS[idx - 1], aS[idx + 1]));

This wont handle if your character is at position zero and some other conditions, you’ll have to figure them out.

2

solved C# get position of a character from string