Count no of characters from string
startIndex = k.IndexOf(" 43 ");
string test3 = k.Substring(startIndex, 32);
startIndex1 = k.IndexOf(" 54 ");
string test4 = k.Substring(startIndex, 55);
how to count no of characters between 2 indexes(startIndex and startIndex1) from a string in c#?
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Kirtan PatelRank #292 · 8.6K reputationPosted Sep 17, 2009, 1:00 AM EDT
Dont forget to mark "Do you like answer" if answer helped you :)
Hi, mittal
Here is Code for it it it is not what you want then provide me sample String on Which you re performing the operation and Also tell me What you want as Result
private void button1_Click(object sender, EventArgs e)
{
string x = textBox1.Text.Trim();
int Index1 = x.IndexOf("43");
int Index2 = x.IndexOf("54");
MessageBox.Show("Number of Chars Between :=" + (Index2 - Index1-1).ToString());
}
Roei BarRank #1,271 · 1.4K reputationPosted Sep 17, 2009, 3:38 AM EDT
startIndex = k.IndexOf(" 43 ");
startIndex1 = k.IndexOf(" 54 ");
string test3 = k.Substring(43, 54-43);
then
int _totalChars = test3.Trim().Length;