-3

I have this line in my C# code:

s_ind = formula.LastIndexOfAny(operators, 1);

Where operators is a char array with elements, +, -, *, /, and ^

formula is a string equal to "182+0"

The expression is returning -1, so it is saying there is no plus sign in the string "182+0"

What is going wrong?

4

1 回答 1

4

1告诉从LastIndexOfAny位置 1 开始并向搜索。由于您+在位置 1之后,因此找不到它。

如果你想找到最后一次出现,只需使用:

s_ind = formula.LastIndexOfAny(operators);

来自MSDN

搜索从指定的字符位置开始,然后向后向字符串的开头进行

于 2013-07-29T19:14:42.023 回答