tokenizer

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Newsey Person

    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.prin tln( t.sval ); // This line works perfectly
    System.out.prin tln( 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






  • Murray

    #2
    Re: tokenizer


    "Newsey Person" <NOspam@blueyon der.co.uk> wrote in message
    news:hObmd.3652 2$Q7.34534@fe1. news.blueyonder .co.uk...[color=blue]
    >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.prin tln( t.sval ); // This line works perfectly
    > System.out.prin tln( 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[/color]

    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


    Comment

    • Murray

      #3
      Re: tokenizer


      "Newsey Person" <NOspam@blueyon der.co.uk> wrote in message
      news:hObmd.3652 2$Q7.34534@fe1. news.blueyonder .co.uk...[color=blue]
      >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.prin tln( t.sval ); // This line works perfectly
      > System.out.prin tln( 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
      >[/color]

      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.


      Comment

      • IchBin

        #4
        Re: tokenizer

        Murray wrote:[color=blue]
        > "Newsey Person" <NOspam@blueyon der.co.uk> wrote in message
        > news:hObmd.3652 2$Q7.34534@fe1. news.blueyonder .co.uk...
        >[color=green]
        >>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.pr intln( t.sval ); // This line works perfectly
        >>System.out.pr intln( 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
        >>[/color]
        >
        >
        > 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.
        >
        >[/color]
        Look at:


        --


        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

        Comment

        • Newsey Person

          #5
          Re: tokenizer

          Thanks for the help and advice,

          It works a treat now.

          Newsey

          "Murray" <parps@SMAFFoff SPAMMER.optusne t.SPAMMAGE.com. au> wrote in message
          news:DJjmd.3797 5$K7.4460@news-server.bigpond. net.au...[color=blue]
          >
          > "Newsey Person" <NOspam@blueyon der.co.uk> wrote in message
          > news:hObmd.3652 2$Q7.34534@fe1. news.blueyonder .co.uk...[color=green]
          > >I have a StreamTokenizer ( t ) iterating over a *.txt file and I am[/color][/color]
          having[color=blue][color=green]
          > > trouble in catching words I am searching for ...
          > >
          > > Some lines have obviously been left out for clarity.
          > >
          > > System.out.prin tln( t.sval ); // This line works perfectly
          > > System.out.prin tln( t.sval.toString ); // As does this one
          > >
          > > If I evaluate ( t.sval.toString .getClass ), I get a String class[/color][/color]
          reported.[color=blue][color=green]
          > >
          > > 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
          > >[/color]
          >
          > 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.
          >
          >[/color]


          Comment

          • Randolf Richardson

            #6
            Re: tokenizer

            ""Newsey Person" <NOspam@blueyon der.co.uk>" wrote in comp.lang.java:

            [sNip][color=blue]
            > Thanks for the help and advice,
            >
            > It works a treat now.[/color]

            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.

            Comment

            Working...