Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Wednesday, November 5, 2008 6:24 PM
TextBox21.Text.Replace("delete", "");
If yes, is there something I can do to make it not case sensitive?
-smc
All replies (4)
Wednesday, November 5, 2008 7:24 PM ✅Answered
string newtext = TextBox21.TExt.ToUpper().Replace("DELETE", "");
Now that will return the whole content in upper case.
If you want true case insensitive replace, check out hte following article:
http://www.codeproject.com/KB/string/fastestcscaseinsstringrep.aspx
Wednesday, November 5, 2008 11:31 PM ✅Answered
Hi,
You can achieve this by using Regex.Replace method provided under System.Text.RegularExpressions
You can use that as
Regex.Replace(TextBox21.Text, "delete", "", RegexOptions.IgnoreCase);
Hope this helps you.
Thursday, November 6, 2008 12:53 AM ✅Answered
Is REPLACE case sensitive?
What result did you get when you tried? What does the documentation say (http://msdn.microsoft.com/en-us/library/fk49wtc1.aspx)? We are here to help, but you'll help yourself by making a small effort yourself first. We may not always be here for you...
is there something I can do to make it not case sensitive?
Not according to the documentation. You'll have to use a different method. The suggested use of regular expressions will work, but is rather expensive in terms of time. The use of .ToUpper() has the sideeffect of making the result loose it's initial casing, and is also expensive.
If you want it to be fast, you can use the String.IndexOf() method (http://msdn.microsoft.com/en-us/library/system.string.indexof.aspx) which does have an overload to control the case-sensitivity, to find occurrences to replace, and then depending on the situation, use a StringBuilder to build the final result.
You'll probably be fine with the RegEx method suggested.
Thursday, November 6, 2008 12:57 PM
If you want to know, the replace method is case sensitive, and so, if you eval "delete" against "DELETE" the answer will be false, because they aren't equals. You can use Regular Expressions as the others pals said.
Seeya