String.indexOf issues with : character

R

Ron Loewy

Hi,

I am using JBuilder 4 (I know, it is old) and java -version returns the
following:

java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)

I have an issue when searching for a substring using the indexOf method of
the String class, when the : character exists.

For example - I have a very long string that in it has the substring
[:FirstDateStr]

When I search for FirstDateStr or FirstDateStr]
(Source.indexOf("FirstDateStr]") - I get the value 424
When I search for :FirstDateStr or :FirstDateStr]
(Source.indexOf(":FirstDateStr]") - I get the value -1
Here is the crazy stuff -
When I search for [FirstDateStr] (Source.indexOf("[FirstDateStr]") I get 423

It seems as if the : is ignored in the source string, but not in the
substring I am searching for.

Any ideas what I am doing wrong?

Thanks,
Ron.
 
G

Gordon Beaton

I have an issue when searching for a substring using the indexOf
method of the String class, when the : character exists.

For example - I have a very long string that in it has the substring
[:FirstDateStr]

When I search for FirstDateStr or FirstDateStr]
(Source.indexOf("FirstDateStr]") - I get the value 424
When I search for :FirstDateStr or :FirstDateStr]
(Source.indexOf(":FirstDateStr]") - I get the value -1
Here is the crazy stuff -
When I search for [FirstDateStr] (Source.indexOf("[FirstDateStr]") I get 423

It seems as if the : is ignored in the source string, but not in the
substring I am searching for.

Any ideas what I am doing wrong?

Probably one of your strings doesn't contain exactly what you think it
does. If you write a 5 line program containing only hardcoded values,
do you have the same problem?

/gordon
 
R

Ron Loewy

Gordon Beaton said:
I have an issue when searching for a substring using the indexOf
method of the String class, when the : character exists.

For example - I have a very long string that in it has the substring
[:FirstDateStr]

When I search for FirstDateStr or FirstDateStr]
(Source.indexOf("FirstDateStr]") - I get the value 424
When I search for :FirstDateStr or :FirstDateStr]
(Source.indexOf(":FirstDateStr]") - I get the value -1
Here is the crazy stuff -
When I search for [FirstDateStr] (Source.indexOf("[FirstDateStr]") I get 423

It seems as if the : is ignored in the source string, but not in the
substring I am searching for.

Any ideas what I am doing wrong?

Probably one of your strings doesn't contain exactly what you think it
does. If you write a 5 line program containing only hardcoded values,
do you have the same problem?

Actually, the code for both the string and the search string was created by
the same application - so I will be surprised if they do not match (I have
the same code in another language (Delphi) on the same strings and it works
perferctly. I will check it out.

Thanks,
Ron.
 
D

Dario

Ron said:
Hi,

I am using JBuilder 4 (I know, it is old) and java -version returns the
following:

java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)

I have an issue when searching for a substring using the indexOf method of
the String class, when the : character exists.

For example - I have a very long string that in it has the substring
[:FirstDateStr]

When I search for FirstDateStr or FirstDateStr]
(Source.indexOf("FirstDateStr]") - I get the value 424
When I search for :FirstDateStr or :FirstDateStr]
(Source.indexOf(":FirstDateStr]") - I get the value -1
Here is the crazy stuff -
When I search for [FirstDateStr] (Source.indexOf("[FirstDateStr]") I get 423

It seems as if the : is ignored in the source string, but not in the
substring I am searching for.

Any ideas what I am doing wrong?

Nothing wrong.

Simply: your very long string
does not contains the substring ":FirstDateStr" !

- Dario
 

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,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top