indexOf("USA")

Hello All,

I am having a very simple java question.

Sample XML:

<?xml version="1.0" encoding="ISO-8859-1" ?>

- <!-- Edited with XML Spy v4.2

-->

- <USA>

<to></to>

<from>Jani</from>

<heading>Reminder</heading>

</USA>

I am using a method in the SeeBeyond JCD:

indexOf("USA")method - this method is returning me always as false even though my XML has USA in it.

I don't understand what the problem is?

Christina

[587 byte] By [christinataylor_javaa] at [2007-10-2 0:48:45]
# 1
> indexOf("USA")method - this method is returning me> always as false even though my XML has USA in it.Are you sure? indexOf() returns int.> I don't understand what the problem is?Neither do I. Why don't you post your code?
Annie.a at 2007-7-15 17:58:50 > top of Java-index,Java Essentials,Java Programming...
# 2
That isn't a "java question". I see nothing to do with java there. So you have an XML file. So you have this mystical thing called the "SeeBeyond JCD" whatever that is. There's no java code you're showing at all, that an answer can be directed towards.
warnerjaa at 2007-7-15 17:58:50 > top of Java-index,Java Essentials,Java Programming...
# 3

I am really sorry for that.

Java code is as below:

if (((getin().getClient().getPayload().toString()).indexOf("USA") > 0))

{

EGate.collabTrace("I am here ...There is USA in the XML....1");

}

else

{

EGate.collabTrace("I am here .......4.....there is no USA in this XML");

}

I am always getting the message: "I am here .......4.....there is no USA in this XML"

christinataylor_javaa at 2007-7-15 17:58:50 > top of Java-index,Java Essentials,Java Programming...
# 4

> if (((getin().getClient().getPayload().toString()).indexOf("USA") > 0))

So debug it.

String test = getin().getClient().getPayload().toString();

System.out.println("The string is: " + test);

Obviously it doesn't have "USA" in it (beyond the first character anyway), or that "if" statement would have been true.

Note: you should be checking for >= 0, not just > 0. It returns < 0 if the substring isn't found.

warnerjaa at 2007-7-15 17:58:50 > top of Java-index,Java Essentials,Java Programming...