在字符串中查找字符串 [英] find a string inside string
本文介绍了在字符串中查找字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我需要在字符串中找到一个字符串并删除其余字符串。
我的字符串将是220,220,220,220
我需要从上面的字符串格式中删除一个220.
任何想法请。
Hi All,
I need find a string inside a string and remove rest of the string.
my string will be 220,220,220,220
I need to remove only one 220 from above string format.
Any idea please.
推荐答案
请尝试以下方法:
Try the following:
string input = "my string will be 220,220,220,220";
string find = "220";
int searchIndex = input.IndexOf(find);
input = (searchIndex < 0) ? input : input.Remove(searchIndex, find.Length);
我刚刚注意到你用 VB.NET $标记了你的问题c $ c>所以这是该语言的版本:
I've just noticed you tagged your question with VB.NET
so here is the version for that language:
Dim input = "my string will be 220,220,220,220"
Dim find = "220"
Dim searchIndex = input.IndexOf(find)
input = If((searchIndex < 0), input, input.Remove(searchIndex, find.Length))
这篇关于在字符串中查找字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文