【问题标题】:How to find character after pipe "|" in C#如何在 C# 中查找管道 \"|\" 之后的字符
【发布时间】:2022-11-21 08:19:27
【问题描述】:

我想在 | 之后找到字符并在 C# 中检查循环。

就像我有Test|T1。在管道之后,字符可以是Test|T2Test|T3 之类的任何东西。

第一个值是Table|Y,第二个值可以是Test|T1Test|T2Test|T3

所以我想在 else 块中检查 | 之后的字符。

  foreach (var testing in TestQuestion.Split(','))
  {
       if(testing.Equals("Table|Y"))
            {
        order.OrderProperties.Add(new OrderProperty("A")
        {
          ...
        });
        }

     else
          {
        //check the value after "|"
      }
                        
    

 }

所以我想在 else 块中检查 | 之后的字符。

【问题讨论】:

  • string.Split('|')
  • @stuartd,如果我将字符串拆分为string.Split('|'),那么我只会得到Test。我需要 | 之后的字符,例如 T1T2T3

标签: c#


【解决方案1】:

您可以这样做(例如测试值是否为 T1):

if (testing.Split('|')[0] == "Test" && testing.Split('|')[1] == "T1")
{
    
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-05-15
    • 1970-01-01
    • 2012-02-10
    • 2015-09-10
    • 2014-09-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-16
    相关资源
    最近更新 更多