String comparison error that I cannot track

B

bjjnova

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 }
}
 
J

John G Harris

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.
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top