473,387 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 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 1546
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: David Graham | last post by:
Hi I have been busy going through the last weeks postings in an attempt to absorb javascript syntax (I guess it's not possible to just absorb this stuff in a passive way - I'm getting way out of...
74
by: Michael | last post by:
As if we needed another string reversal question. I have a problem with the following code, that I believe should work. int StringReverse(char* psz) { char *p = psz; char *q = psz +...
51
by: Alan | last post by:
hi all, I want to define a constant length string, say 4 then in a function at some time, I want to set the string to a constant value, say a below is my code but it fails what is the correct...
5
by: Danilo Kempf | last post by:
Folks, maybe one of you could be of help with this question: I've got a relatively portable application which I'm extending with a plugin interface. While portability (from a C perspective) is...
26
by: junky_fellow | last post by:
Consider the following piece of code: char *str = "Hello"; if (str = "Hello") printf("\nstring matches\n"); str is pointer to char and "Hello" is a string literal whose type is "array of...
26
by: Neville Lang | last post by:
Hi all, I am having a memory blank at the moment. I have been writing in C# for a number of years and now need to do something in VB.NET, so forgive me such a primitive question. In C#, I...
2
by: sandy | last post by:
I am trying to upper case a string, so I have this method: string FileSystem::toupper(string S) { for (int i=0; i<S.length(); ++i) { S=toupper(S); } return S;
9
by: chutsu | last post by:
hi I got a simple program, and I was wondering how do you check if the string in an array = a string. For example if I put "APPLE" in array Array then how can I check it with a if statement. if...
21
by: phpCodeHead | last post by:
Code which should allow my constructor to accept arguments: <?php class Person { function __construct($name) { $this->name = $name; } function getName()
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.