C # Substring and ToUpper

I use substring and IndexOf to determine the value inside the string, but my code does not work if the string (strOldValue) below contains any string otherwise. Therefore, if strOldValue contains Test or TEST, my substring fails. How can I add ToUpper to this script? Forgive my ignorance, I am new to .Net.

String strValue = strOldValue.Substring(strOldValue.IndexOf(@"test"));

Thanks C

+3
source share
5 answers

Using ToUpper, this will be done as follows:

String strValue = strOldValue.Substring(
                    strOldValue.ToUpper().IndexOf(@"TEST"));

However, the easiest way would be to indicate that the comparison should not be case-sensitive:

String strValue = strOldValue.Substring(strOldValue.IndexOf(@"TEST",
          StringComparison.CurrentCultureIgnoreCase));

compareType IndexOf , : , (. http://msdn.microsoft.com/en-us/library/ms224425.aspx ).

+16
String strValue 
    = strOldValue.Substring(strOldValue.ToUpper().IndexOf(@"TEST"));

. , ( " ToUpper?" ).

, .

divo/TheSoftwareJedi .

+3

String.IndexOf(String,StringComparison), , . ToUpper(), - String, Garbage Collector. , , , .

+2
strValue.Substring(strValue.IndexOf("TEST", StringComparison.OrdinalIgnoreCase));
+1

, :

String strValue = new Regex("test.*",
       RegexOptions.IgnoreCase).Match(strOldValue).Value;
0

All Articles