How to compare strings?

R

Rhonda

I have 2 strings that I want to compare. The typical JScript string compare
doesn't work?

What I want

var a = "RB";
var b = "RC";

if (a == b)
{
do something
}

I've tried something like this but it didn't work.
var c = String.Compare(a, b);

Any help would be appreciated.

Thanks,
 
M

mag31

Hi Rhonda,

If JScript works anything like Java, .Net or other object orientated
languages then comparing two strings is not straightforward.

The strings are stored in memory. the variables "a" or "b" then point to the
string in memory. doing == compares the memory locations of the strings.
However, you may have "ab", and "ab" but stored in different memory
locations. To compare the values you need to do:

a.Equals(b)

Hope this works for you,
Mark Grant
Cambridge Convergence Limited
www.cambridgeconvergence.com
 
S

Steve van Dongen [MSFT]

I have 2 strings that I want to compare. The typical JScript string compare
doesn't work?

What I want

var a = "RB";
var b = "RC";

if (a == b)
{
do something
}

Any help would be appreciated.

How about posting some of your code?

Regards,
Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top