尝试检查某个位置是否包含 C# 中的某个字符

Trying to check if a certain position contains a certain character in C#

我需要检查字符串的倒数第三个和倒数第四个位置是否包含点。我不确定该怎么做。我为此使用 string.Contains 吗?我需要用它制作一个数组吗?我对此一头雾水。

yourString.IndexOf(".", yourString.Length - 5, 2) != -1

你要找的是绝对位置,所以Contains不行,但是[..]Length:

  string myString = "dots . dots and .dot";

  int index = 4; // one based
  char charToTest = '.';

  // if index'th character is charToTest:
  //  1. the string is long enough 
  //  2. it has charToTest at Length - index position
  if (myString.Length >= index && 
      myString[myString.Length - index] == charToTest) {
    ... 
  }