From: Raj on 9 Nov 2009 04:38 string str1="rakshith"; if(str1.ToUpper()=="RAKSHITH") { //DO SOMETHING } Console.WriteLine("str1 value is : " + str1); //prints as "RAKSHITH if(UCase(str1)=="RAKSHITH") { //DO SOMETHING } Console.WriteLine("str1 value is: " + str1); //prints as rakshith Seems ToUpper() makes str1 mutable whereas in C# it is not!! Any help would be appreciated Thank you Regards Raj
From: Patrice on 9 Nov 2009 05:33 Hello, > string str1="rakshith"; > if(str1.ToUpper()=="RAKSHITH") > { > //DO SOMETHING > } > Console.WriteLine("str1 value is : " + str1); > //prints as "RAKSHITH This is not what I'm seeing (it prints "rakshith" as expected). If you have some code instead of // DO SOMETHING double check you are not altering str1 ?... Also not sure if the issue is VB or C# related. A c# group might be better as you seems to provide only C# code... -- Patrice
From: Herfried K. Wagner [MVP] on 9 Nov 2009 09:02 Raj schrieb: > string str1="rakshith"; > if(str1.ToUpper()=="RAKSHITH") > { > //DO SOMETHING > } > Console.WriteLine("str1 value is : " + str1); > //prints as "RAKSHITH .... only if the string variable 'str1' already contains "RAKSHITH". BTW, I suggest using 'String.Compare' instead of comparing upper-case values. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
From: Joe Cool on 9 Nov 2009 11:20 On Nov 9, 9:02 am, "Herfried K. Wagner [MVP]" <hirf-spam-me- h...(a)gmx.at> wrote: > Raj schrieb: > > > string str1="rakshith"; > > if(str1.ToUpper()=="RAKSHITH") > > { > > //DO SOMETHING > > } > > Console.WriteLine("str1 value is : " + str1); > > //prints as "RAKSHITH > > ... only if the string variable 'str1' already contains "RAKSHITH". > > BTW, I suggest using 'String.Compare' instead of comparing upper-case > values. > Other than the fact that String.Compare exists, is there any other reason to use it instead of comparing upper (or lower) case values to determine equality?
From: Joe Cool on 9 Nov 2009 13:34 On Nov 9, 11:20 am, Joe Cool <joecool1...(a)live.com> wrote: > On Nov 9, 9:02 am, "Herfried K. Wagner [MVP]" <hirf-spam-me- > > > > > > h...(a)gmx.at> wrote: > > Raj schrieb: > > > > string str1="rakshith"; > > > if(str1.ToUpper()=="RAKSHITH") > > > { > > > //DO SOMETHING > > > } > > > Console.WriteLine("str1 value is : " + str1); > > > //prints as "RAKSHITH > > > ... only if the string variable 'str1' already contains "RAKSHITH". > > > BTW, I suggest using 'String.Compare' instead of comparing upper-case > > values. > > Other than the fact that String.Compare exists, is there any other > reason to use it instead of comparing upper (or lower) case values to > determine equality? Actually a co-worker reminded me that our staff had talked about this several months ago. The advantage of using String.Compare is that the ToUpper and ToLower methods actually create a new string in memory and the memory is not released until the garbage collector kicks in. So using String.Compare instead of using ToUpper or ToLower to perform case-insensitve compares can save on memory.
|
Next
|
Last
Pages: 1 2 3 Prev: Socket stuck in CLOSE_WAIT Next: Help accesing clarion TPS file structure |