I am trying to count the number of semicolons ; in a string. I have tried a variety of methods to no avail in that each way I have tried I only get the length of the string returned.
Neither way has worked. Any suggestions would be apprecaited. I think it might be because I am just comparing objects of type eg IF sees both as being characters so therefore it says it's true and moves on.
Code:
// one attempted method
for (int i = 0; i < v_myIngredients.Length; i++)
{
if(String.Equals(v_myIngredients.Substring(v_myIngredients.IndexOf(";")),";"))
{
listCount++;
}
}
// other attempted method
for (int i = 0; i < v_myIngredients.Length; i++)
{
if(v_myIngredients.Substring(v_myIngredients.IndexOf(";")==";"))
{
listCount++;
}
}
Neither way has worked. Any suggestions would be apprecaited. I think it might be because I am just comparing objects of type eg IF sees both as being characters so therefore it says it's true and moves on.