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 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
"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.
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
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.
""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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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;...
|
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...
|
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...
|
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...
|
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')
|
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...
|
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...
|
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...
|
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...
|
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,...
|
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$) {
}
...
|
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...
|
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
|
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...
|
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...
|
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,...
|
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...
|
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,...
| |