gpt4 book ai didi

c# - 如何检查标签是否包含字符串的一部分

转载 作者:太空宇宙 更新时间:2023-11-03 12:55:05 25 4
gpt4 key购买 nike

我正在尝试检查我的标签是否仅包含字符串的一部分。假设在我的 Label.Text 中我有“Food : 100 ”,我想检查它是否包含 Food ,然后使用子字符串剪切前 7 位数字(包括空格),然后得到数字 100 我怎么能做这个 ?这是正确的方法吗?感谢任何帮助

我试着用 linq 来做,但它不会工作,因为它是标签

 if (status.Text.Any(x => x.Contains("Food")))
{
//do somne work
}

最佳答案

这将是解决这个问题的一个选项。但是我没有使用 Substring(),而是使用了 Remove()

var labelText = Label.Text;
var foodValue = "";

if(labelText.Contains("Food"))
foodValue = labelText.Remove(0,7);

执行该代码后,您可以在 foodValue 中找到值 100。

关于c# - 如何检查标签是否包含字符串的一部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34181442/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com