I’m having a problem getting an index of the character ‘-‘ of a string. Let me explain my problem.
First I have to read a line from a text file. The only line in the text file is “Beta = 62.5 * (Sigma – Delta) / 125”
StreamReader rdr = new StreamReader(openPath, Encoding.Default);
while (rdr.Peek() != -1)
{
string strInput = rdr.ReadLine();
}
then I need to get the index of char ‘-‘.
int col = strInput.IndexOf('-');
After the above line ‘col’ is equal to -1. But as you can see the ‘-‘ character is in the above mentioned string which read from the text file.
I couldn’t figure out why I’m getting -1 as the index of ‘-‘. help me…
Those two characters are not the same. Look at the length of them:
(this is called an en-dash, equal to the width of the ASCII character N)
vs
(this is a normal ascii hyphen, or minus sign)
Amend your indexof to use the en-dash (–) instead of the hyphen (-) and you should get proper results.
Edit: Thanks to sixlettervariables for correct terminology