473,609 Members | 1,868 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 vTODChgDocItera tor = vTODChgDocColle ction.iterator( );
vTODChgDocItera tor.hasNext(); )
{
var vTODChgDocPoint er = vTODChgDocItera tor.next()
vTODChgDoc = vTODChgDocColle ction.get(vTODC hgDocPointer)
var vTODChgDocName = vTODChgDoc.name
var vMSBChgDocName = childType.name
print ("vTODChgDoc.na me = " + 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 1559
In article <11************ **********@t31g 2000cwb.googleg roups.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 vTODChgDocItera tor = vTODChgDocColle ction.iterator( );
vTODChgDocIter ator.hasNext(); )
{
var vTODChgDocPoint er = vTODChgDocItera tor.next()
vTODChgDoc = vTODChgDocColle ction.get(vTODC hgDocPointer)
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.na me = " + 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
23379
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 my depth with most of the posts, I will buy a good book and take some online tutorials) Anyway, I think I almost understand one of Mr Nielsen's posts on form validation. It all centers around whether I am interpreting an empty string correctly -...
74
5039
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 + strlen(psz) - 1; while (p < q) {
51
8253
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 code? many thx!
5
2526
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 going to hell just by using dlopen()/LoadLibrary() respectively, I'm still trying to get it as clean as possible. I have a number of different quantums of data and a number of plugins. Since any plugin can (and possibly will) touch any quantum...
26
563
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 char". How can we compare two different objects for equality ? Is some conversion is being done before that comparison ?
26
3794
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 test whether a string has a value or not by the following syntax: if (thisString.Trim() == "") {
2
4429
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
2843
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 (Array == 'APPLE'){ do something; } or do I need to use a different method to check?
21
55603
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
8139
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8091
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8232
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6064
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5524
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4032
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4098
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1686
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1403
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.