From: Herfried K. Wagner [MVP] on
Joe Cool 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?

I assume that 'String.Compare' is semantically more correct than
comparing the upper-case versions of the strings. The reason for this
is that there are certain conversion rules for the lower-case to
upper-case conversion (actually in some cultures characters are
decomposed and thus result in multiple characters in the upper-case
version).

However, note that the '=' operator in VB will use VB's intrinsic string
comparison mechanism, which either performs a binary or a text
comparison depending on the 'Option Compare' Setting.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
From: Scott M. on

"Raj" <Raj(a)discussions.microsoft.com> wrote in message
news:9774D603-A711-4E57-88C1-5521CB90B989(a)microsoft.com...
> 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

I don't get those results (nor did I expect to). They both return the
original lower case version.

The reason being is that both of these create a new string that is made up
of the result of the method and you are not actually creating a reference to
that newly created string, you are just writing out the original string.

-Scott


From: David Anton on
That's not VB.
Also, C# does not allow using "UCase" unqualified even if you're referencing
the VisualBasic assembly.

Neither 'UCase' nor 'ToUpper' modify the string in-place. Both the VB
global function and the .NET string 'ToUpper' method return new strings.
--
David Anton
Convert between VB, C#, C++, & Java (http://www.tangiblesoftwaresolutions.com)


"Raj" wrote:

> 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: Family Tree Mike on
David Anton wrote:
> That's not VB.
> Also, C# does not allow using "UCase" unqualified even if you're referencing
> the VisualBasic assembly.
>
> Neither 'UCase' nor 'ToUpper' modify the string in-place. Both the VB
> global function and the .NET string 'ToUpper' method return new strings.

Well, this is a VB.net question...

For what it is worth, you can use the following in C#:

static void Main(string[] args)
{
string s = Microsoft.VisualBasic.Strings.UCase("Fred");
Console.WriteLine(s);
Console.ReadKey();
}

Just add a reference to Microsoft.VisualBasic.

--
Mike
From: Herfried K. Wagner [MVP] on
Family Tree Mike schrieb:
>> Also, C# does not allow using "UCase" unqualified even if you're
>> referencing the VisualBasic assembly.
>>
>> Neither 'UCase' nor 'ToUpper' modify the string in-place. Both the VB
>> global function and the .NET string 'ToUpper' method return new strings.
>
> Well, this is a VB.net question...
>
> For what it is worth, you can use the following in C#:
>
> static void Main(string[] args)
> {
> string s = Microsoft.VisualBasic.Strings.UCase("Fred");
> Console.WriteLine(s);
> Console.ReadKey();
> }
>
> Just add a reference to Microsoft.VisualBasic.

Yep, but you are using 'UCase' qualified by the namespace and module
name. C# doesn't support importing modules, making it possible to use
the function without further qualification.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>