相关疑难解决方法(0)

在字符串中查找两个值之间的单词

我有一个txt文件作为字符串,我需要找到两个字符和Ltrim/或Rtrim其他所有字之间的单词.它可能必须是有条件的,因为两个字符可能会根据字符串而改变.

例:

car= (data between here I want) ;
car =  (data between here I want) </value>
Run Code Online (Sandbox Code Playgroud)

码:

int pos = st.LastIndexOf("car=", StringComparison.OrdinalIgnoreCase);

if (pos >= 0)
{
     server = st.Substring(0, pos);..............
}
Run Code Online (Sandbox Code Playgroud)

.net c# string substring indexof

3
推荐指数
2
解决办法
2万
查看次数

如何在句子文本中搜索单词 [C#]

我不知道如何在 C# 中搜索一个句子的单词。如果这个词在句子中的任何地方。

我的计划是,如果有我在任何地方设置的词,button1 将可见。

例如 => 我在 label1 中设置了“ABC”这个词。

如果 textbox1 中的句子是 : I'am ABC. or : ABC is here. or : The ABC is come. or :12345ABCDEFG

Button1 将可见。

我试过编码:

string textToSearchFor = "ABC";
int index = textbox1.Text.IndexOf(textToSearchFor, StringComparison.OrdinalIgnoreCase);
if (index >= 0)
{
    button1.Visible = true;
}
else
{
    button1.Visible = false;
}
Run Code Online (Sandbox Code Playgroud)

但它没有按计划进行。

-编辑-

因为当 textbox1 中的值是ABCbutton1.Visible 是 true

但是当 textbox1 值为ABC is here.or 时The ABC is come.button1.Visible 为 …

c# visual-studio

2
推荐指数
1
解决办法
104
查看次数

标签 统计

c# ×2

.net ×1

indexof ×1

string ×1

substring ×1

visual-studio ×1