在VB.net全部替换功能(Replace All Function in VB.net)

2019-09-26 03:39发布

我怎么能替换字符串varaiable像所有字符串

dim str = "I am testing and testing and testing"

更换后“和”

ReplaceAll(str,"and","or")

我怎么能代替所有情况下insentive不区分sensative?

Answer 1:

听起来像是正则表达式的情况下:

从http://weblogs.asp.net/jgalloway/archive/2004/02/11/71188.aspx

using System.Text.RegularExpressions;

string myString = "find Me and replace ME";
string strReplace = "me";

myString = Regex.Replace(myString, "me", strReplace, RegexOptions.IgnoreCase);


Answer 2:

    Dim str As String = "I am testing and testing and testing"
    str = str.Replace("and", "or")


Answer 3:

尽管使用正则表达式的,由马特和RQDQ的建议,你可以使用VB糖,如:

Replace(expression, find, replacement, start, count, compare)

从文档 。



文章来源: Replace All Function in VB.net