471,337 Members | 996 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,337 software developers and data experts.

String comparison error that I cannot track

I have the following string comparison that is throwing an error I
cannot find ( I will include my attempts to trace the error)

In the line following the asterisks, written as I have below, a true is
always returned and the printed msg appears that the 2 variables are
not equal. This happens even when the print statement writes out,
"Change Doc Types TASK and TASK are not equal". (So, even when I test
each variable separately and it evaluates to "TASK", I still get a true
on the first condition telling me that "TASK" and "TASK" are not
equal).

If I test by setting either variable to the thing I am testing for
(e.g., "TASK") the first test evaluates to false and the else statement
is executed (this is the expected result).

If I change the condition to read

if (vTODChgDocName == "TASK" && vMSBChgDocName != "TASK") the first
condition evaluates to false, and the else executes.

The "error" only occurs when I am testing vTODChgDocName against
vMSBChgDocName.

CODE:

for (var vTODChgDocIterator = vTODChgDocCollection.iterator();
vTODChgDocIterator.hasNext(); )
{
var vTODChgDocPointer = vTODChgDocIterator.next()
vTODChgDoc = vTODChgDocCollection.get(vTODChgDocPointer)
var vTODChgDocName = vTODChgDoc.name
var vMSBChgDocName = childType.name
print ("vTODChgDoc.name = " + vTODChgDocName + " , vMSBChgDocName = " +
vMSBChgDocName)

// ******* error is occuring in the following line ********************
if (vTODChgDocName != vMSBChgDocName)
{

print ("Change Doc Types " + vTODChgDocName + " and " + vMSBChgDocName
+ " are not equal\n")

}
else
{
print ("Found " + vTODChgDocName + " in TOD")
vTODChgDocFound = 1 }
}

Apr 25 '06 #1
1 1445
In article <11**********************@t31g2000cwb.googlegroups .com>,
bjjnova <bj*****@gmail.com> writes
I have the following string comparison that is throwing an error I
cannot find ( I will include my attempts to trace the error)

In the line following the asterisks, written as I have below, a true is
always returned and the printed msg appears that the 2 variables are
not equal. This happens even when the print statement writes out,
"Change Doc Types TASK and TASK are not equal". (So, even when I test
each variable separately and it evaluates to "TASK", I still get a true
on the first condition telling me that "TASK" and "TASK" are not
equal).

If I test by setting either variable to the thing I am testing for
(e.g., "TASK") the first test evaluates to false and the else statement
is executed (this is the expected result).

If I change the condition to read

if (vTODChgDocName == "TASK" && vMSBChgDocName != "TASK") the first
condition evaluates to false, and the else executes.

The "error" only occurs when I am testing vTODChgDocName against
vMSBChgDocName.

CODE:

for (var vTODChgDocIterator = vTODChgDocCollection.iterator();
vTODChgDocIterator.hasNext(); )
{
var vTODChgDocPointer = vTODChgDocIterator.next()
vTODChgDoc = vTODChgDocCollection.get(vTODChgDocPointer)
var vTODChgDocName = vTODChgDoc.name
var vMSBChgDocName = childType.name
Are the names String *objects*, as opposed to primitive string values ?
If they are, then ...
print ("vTODChgDoc.name = " + vTODChgDocName + " , vMSBChgDocName = " +
vMSBChgDocName)

// ******* error is occuring in the following line ********************
if (vTODChgDocName != vMSBChgDocName)
.... change this to

if (vTODChgDocName.valueOf() != vMSBChgDocName.valueOf())

I expect you know why; if not just ask.
{

print ("Change Doc Types " + vTODChgDocName + " and " + vMSBChgDocName
+ " are not equal\n")

}
else
{
print ("Found " + vTODChgDocName + " in TOD")
vTODChgDocFound = 1 }
}


--
John Harris
Apr 25 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by David Graham | last post: by
74 posts views Thread by Michael | last post: by
51 posts views Thread by Alan | last post: by
5 posts views Thread by Danilo Kempf | last post: by
26 posts views Thread by junky_fellow | last post: by
26 posts views Thread by Neville Lang | last post: by
2 posts views Thread by sandy | last post: by
9 posts views Thread by chutsu | last post: by
21 posts views Thread by phpCodeHead | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.