【问题标题】:How to search for a string beginning with a certain value?如何搜索以某个值开头的字符串?
【发布时间】:2018-01-11 11:11:29
【问题描述】:

我正在搜索一个数组并尝试查找对象描述。我遇到的问题是尝试使用通配符。如何在我的数组中搜索以“描述:”开头的值。

int[] poss = textlist.Select((b, i) => b == "Description:*" ? i : -1).Where(i => i != -1).ToArray();

string[] Description = new string[poss.Length - 1];

foreach (int pos in poss)
{
    Description = textlist[pos];
}

【问题讨论】:

  • b.Contains("Description")
  • b.StartsWith( "Description:" )

标签: c# arrays string search wildcard


【解决方案1】:
int[] poss = textlist.Select((b, i) => 
    b.StartsWith("Description") ? i : -1).Where(i => i != -1).ToArray();

【讨论】:

    【解决方案2】:

    你可以这样做:

    Description = textlist.Where(s => s.StartsWith("Description:")).ToArray();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-25
      • 2014-12-02
      • 2022-11-13
      • 1970-01-01
      • 2012-07-05
      • 2017-01-08
      • 2020-11-22
      • 1970-01-01
      相关资源
      最近更新 更多