reading from a file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mickey0
    New Member
    • Jan 2008
    • 142

    reading from a file

    hi,
    I have to read a file and check for some tokens (special openTag and closeTag):
    #- is open tag
    -# is close tag
    I put the entire file (2 pages) into a string (Will it be ok? ) and now, what's the best appproch to find #- in the String? charAt() ????

    Thanks..
  • samido
    New Member
    • Oct 2007
    • 52

    #2
    try to use string tokenizing, you can test all charectors in the sring by doing so, e.g.

    StringTokenizer st = new StringTokenizer ("this is a test");
    while (st.hasMoreToke ns()) {
    if(st.nextToken () == '#' ){
    ...
    }
    }

    kind regards: Sam Rabophala

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #3
      The String.indexOf( ) method is an extremely simple and efficient way to look
      for those two small Strings; check the API documentation for the String class.

      kind regards,

      Jos

      Comment

      • mickey0
        New Member
        • Jan 2008
        • 142

        #4
        Originally posted by JosAH
        The String.indexOf( ) method is an extremely simple and efficient way to look
        for those two small Strings; check the API documentation for the String class.
        Jos
        I just used indexOf and charAt()....I hoped to find something better....

        Comment

        • BigDaddyLH
          Recognized Expert Top Contributor
          • Dec 2007
          • 1216

          #5
          Originally posted by mickey0
          I just used indexOf and charAt()....I hoped to find something better....
          Is there something wrong with s.indexof("#_") ?

          Comment

          • mickey0
            New Member
            • Jan 2008
            • 142

            #6
            Originally posted by BigDaddyLH
            Is there something wrong with s.indexof("#_") ?
            no there isn't. But I'm looking for simplicity and performance...f or this I was wondering it...

            Comment

            Working...