Yes, using a regex like
textLine = Regex.Replace(textLine, "CREATE", "ALTER",
RegexOptions.IgnoreCase);
(just like Arne wrote it!)
If that doesn't work, change the CREATE and ALTER in the regex
statement to lowercase.
textLine = textLine.toupper().Replace("CREATE","ALTER");
doesn't work because it's saying that textline equals Upper Case
textline, but with CREATE replaced with ALTER as well.
I recommend using the regex statement, but if you're not up to it,
what you already have is fine.
Oh, yeah, and don't forget to reference System.Text.RegularExpressions
for the regex stuff to work.
-Maximz2005
P.S. You should definetly learn to write Regex statements. There are
lots of programs out there that simplify it greatly. Just google for
regex workbench, regex creator, etc.
On Aug 21, 7:13*pm, Arne Vajhøj <a...@vajhoej.dkwrote:
tshad wrote:
I need to replace a value in a string that could be any case:
CREATE
Create
create
And I don't want to change the case of the whole string. *Just find the work
"Create" and change it to "ALTER".
I am doing this way at the moment which works:
*linePosition = textLine.ToUpper().IndexOf("CREATE");
*if (linePosition -1)
*{
* * *textLine = textLine.Replace(line.Substring(linePosition, 6), "ALTER");
*}
I tried to do:
textLine = textLine.toupper().Replace("CREATE","ALTER");
But that changes the whole line to uppercase.
Is there a better way to do this?
s = Regex.Replace(s, "CREATE", "ALTER", RegexOptions.IgnoreCase);
is simple and readable.
Arne