473,386 Members | 1,795 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,386 software developers and data experts.

tokenizer

I have a StreamTokenizer ( t ) iterating over a *.txt file and I am having
trouble in catching words I am searching for ...

Some lines have obviously been left out for clarity.

System.out.println( t.sval ); // This line works perfectly
System.out.println( t.sval.toString ); // As does this one

If I evaluate ( t.sval.toString.getClass ), I get a String class reported.

But these line don't work even though the "String" is in the *.txt file, all
I get is false for every word
t = = "word"
t.sval = = "word" // Return me a boolean
t.sval.toString = = "word"

How do I match a String to my required String?

Thanks in advance

Newsey


Jul 17 '05 #1
5 2042

"Newsey Person" <NO****@blueyonder.co.uk> wrote in message
news:hO******************@fe1.news.blueyonder.co.u k...
I have a StreamTokenizer ( t ) iterating over a *.txt file and I am having
trouble in catching words I am searching for ...

Some lines have obviously been left out for clarity.

System.out.println( t.sval ); // This line works perfectly
System.out.println( t.sval.toString ); // As does this one

If I evaluate ( t.sval.toString.getClass ), I get a String class reported.

But these line don't work even though the "String" is in the *.txt file,
all
I get is false for every word
t = = "word"
t.sval = = "word" // Return me a boolean
t.sval.toString = = "word"

How do I match a String to my required String?

Thanks in advance

Newsey


This is a very common mistake for beginners. When comparing strings you
should use the equals() method. == is an identity test, i.e. it tests
whether they are the same object, not whether they contain the same value.
== will only work the way you want it to work if you're testing primitive
values.

e.g. t.sval.equals("word")

or usually preferably

"word".equals(t.sval) since then you don't need to take care of null values
Jul 17 '05 #2

"Newsey Person" <NO****@blueyonder.co.uk> wrote in message
news:hO******************@fe1.news.blueyonder.co.u k...
I have a StreamTokenizer ( t ) iterating over a *.txt file and I am having
trouble in catching words I am searching for ...

Some lines have obviously been left out for clarity.

System.out.println( t.sval ); // This line works perfectly
System.out.println( t.sval.toString ); // As does this one

If I evaluate ( t.sval.toString.getClass ), I get a String class reported.

But these line don't work even though the "String" is in the *.txt file,
all
I get is false for every word
t = = "word"
t.sval = = "word" // Return me a boolean
t.sval.toString = = "word"

How do I match a String to my required String?

Thanks in advance

Newsey


Oh and in future, you'd be better off posting to comp.lang.java.help

This group doesn't officially exist, and isn't very active.
Jul 17 '05 #3
Murray wrote:
"Newsey Person" <NO****@blueyonder.co.uk> wrote in message
news:hO******************@fe1.news.blueyonder.co.u k...
I have a StreamTokenizer ( t ) iterating over a *.txt file and I am having
trouble in catching words I am searching for ...

Some lines have obviously been left out for clarity.

System.out.println( t.sval ); // This line works perfectly
System.out.println( t.sval.toString ); // As does this one

If I evaluate ( t.sval.toString.getClass ), I get a String class reported.

But these line don't work even though the "String" is in the *.txt file,
all
I get is false for every word
t = = "word"
t.sval = = "word" // Return me a boolean
t.sval.toString = = "word"

How do I match a String to my required String?

Thanks in advance

Newsey

Oh and in future, you'd be better off posting to comp.lang.java.help

This group doesn't officially exist, and isn't very active.

Look at:
http://mindprod.com/jgloss/streamtokenizer.html

--
Thanks in Advance...
IchBin
__________________________________________________ ________________________

'The meeting of two personalities is like the contact of two chemical
substances:
if there is any reaction, both are transformed.'
- Carl Gustav Jung, (1875-1961), psychiatrist and psychologist
Jul 17 '05 #4
Thanks for the help and advice,

It works a treat now.

Newsey

"Murray" <pa***@SMAFFoffSPAMMER.optusnet.SPAMMAGE.com.au> wrote in message
news:DJ*****************@news-server.bigpond.net.au...

"Newsey Person" <NO****@blueyonder.co.uk> wrote in message
news:hO******************@fe1.news.blueyonder.co.u k...
I have a StreamTokenizer ( t ) iterating over a *.txt file and I am having trouble in catching words I am searching for ...

Some lines have obviously been left out for clarity.

System.out.println( t.sval ); // This line works perfectly
System.out.println( t.sval.toString ); // As does this one

If I evaluate ( t.sval.toString.getClass ), I get a String class reported.
But these line don't work even though the "String" is in the *.txt file,
all
I get is false for every word
t = = "word"
t.sval = = "word" // Return me a boolean
t.sval.toString = = "word"

How do I match a String to my required String?

Thanks in advance

Newsey


Oh and in future, you'd be better off posting to comp.lang.java.help

This group doesn't officially exist, and isn't very active.

Jul 17 '05 #5
""Newsey Person" <NO****@blueyonder.co.uk>" wrote in comp.lang.java:

[sNip]
Thanks for the help and advice,

It works a treat now.


You might want to consider using Regular Expressions for this since it
will make it possible for you to do more advanced searches.

--
Randolf Richardson, pro-active spam fighter - rr@8x.ca
Vancouver, British Columbia, Canada

Sending eMail to other SMTP servers is a privilege.
Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Angus Mackay | last post by:
I remember python having a generic tokenizer in the library. all I want is to set a list of token seperators and then read tokens out of a stream, the token seperators should be returned as...
5
by: Knackeback | last post by:
task: - read/parse CSV file code snippet: string key,line; typedef tokenizer<char_separator<char> > tokenizer; tokenizer tok(string(""), sep); while ( getline(f, line) ){ ++lineNo;...
4
by: Java Guy | last post by:
This must be a classical topic -- C++ stgring tokenizer. I just switched from C to C++ ( in Unix ). It turns out that there is no existing C++ string tokenizer. Searching on the Web, I found...
10
by: Alex | last post by:
I'm looking for a fast way to split a string into individual tokens. The typical format of the string is token1|token2|token3|...|tokenN| and the number of tokens varies (which is why i use a...
10
by: Lorenzo J. Lucchini | last post by:
Do you see any counter-indication to a token extractor in the following form? typedef int token; token ExtractToken(const char** String, char* Symbol); If it finds a valid token at the start...
0
by: Arthur | last post by:
Given a "linemess.py" file with inconsistent line ending: line 1 \r \r\n line \n tokenized as per: import tokenize f=open('linemess.py','r')
1
by: xlar54 | last post by:
Hey guys, Im writing a simple language tokenizer and Im at that point of "10 ways to do it, which is the best"... All I need it to do, is given a string, look inside it for keywords, and replace...
18
by: Robbie Hatley | last post by:
A couple of days ago I dedecided to force myself to really learn exactly what "strtok" does, and how to use it. I figured I'd just look it up in some book and that would be that. I figured...
1
by: JamesHoward | last post by:
I have searched the board and noticed that there isn't really any sort of good implementation of a string tokenizer that will tokenize based on a custom set of tokens and return both the tokens and...
1
by: Karl Kobata | last post by:
Hi Fredrik, This is exactly what I need. Thank you. I would like to do one additional function. I am not using the tokenizer to parse python code. It happens to work very well for my...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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
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,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.