SOF User
SOF User

Reputation: 7840

Replace All Function in VB.net

how can I replace all string in string varaiable like

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

After replace with "and"

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

How can I replace all with case insentive not case sensative?

Upvotes: 1

Views: 9819

Answers (3)

Paulo Santos
Paulo Santos

Reputation: 11587

Despite the use of Regular Expression, as suggested by Matt and RQDQ, you can use the VB sugar, like:

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

From the documentation.

Upvotes: 1

dbasnett
dbasnett

Reputation: 11773

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

Upvotes: 1

RQDQ
RQDQ

Reputation: 15579

Sounds like a case for regular expressions:

From 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);

Upvotes: 4

Related Questions