exttracting the name from the string which i read from file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Karthik Prasath
    New Member
    • Sep 2008
    • 4

    exttracting the name from the string which i read from file

    I read the following line from a file

    Code:
     <th colspan="2"><font color="Brown">ABINAYA N</font></th>
    in this line i want to extract name of the student (ABINAYA N here) how can i do that?

    i will read this line for various 95 students where the students name may differ say(KARTHIK PRASATH K,KEERTHANA N,AJITH M)

    how can i extract name of the students alone???

    pls help me as soon as possible

    advance thanks to you..
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Read the API documentation for the Pattern and Matcher classes.
    Compile a Pattern with the regular expression "\\>([^>]+)\\<" and match for
    group 1 start and end boundaries.

    kind regards,

    Jos

    Comment

    • Karthik Prasath
      New Member
      • Sep 2008
      • 4

      #3
      extracting the string

      I read the following line from a file

      Code:
      <th colspan="2"><font color="Brown">ABINAYA N</font></th>
      in this line i want to extract name of the student (ABINAYA N here) how can i do that?

      i will read this line for various 95 students where the students name may differ say(KARTHIK PRASATH K,KEERTHANA N,AJITH M)

      how can i extract name of the students alone???

      pls help me as soon as possible

      advance thanks to you.

      pls explain with some code
      pls pls pls

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Hi, I removed your other identical thread. I also gave you the solution to your
        problem: create a Pattern given the regexp I showed you; have the Pattern
        create a Matcher and find the start() and end|() boundaries of group #1.
        All you have to do is read the API documentation now.

        kind regards,

        Jos (moderator)

        Comment

        • Nepomuk
          Recognized Expert Specialist
          • Aug 2007
          • 3111

          #5
          As an alternative to Jos' suggestion, you could work with the String.substrin g() method, although regular expressions (the things with Patterns and Matchers) would be much more elegant.

          Greetings,
          Nepomuk

          Comment

          • JosAH
            Recognized Expert MVP
            • Mar 2007
            • 11453

            #6
            Originally posted by Nepomuk
            As an alternative to Jos' suggestion, you could work with the String.substrin g() method
            Which brings you back to exactly the original problem: what are the boundaries
            of that substring?

            kind regards,

            Jos

            Comment

            • Nepomuk
              Recognized Expert Specialist
              • Aug 2007
              • 3111

              #7
              Originally posted by JosAH
              Which brings you back to exactly the original problem: what are the boundaries of that substring?
              String.indexOf( ...) (and related methods) should be quite helpful finding those.

              Greetings,
              Nepomuk

              Comment

              • JosAH
                Recognized Expert MVP
                • Mar 2007
                • 11453

                #8
                Originally posted by Nepomuk
                String.indexOf( ...) (and related methods) should be quite helpful finding those.

                Greetings,
                Nepomuk
                Sure, but the substring() method doesn't help a bit; it can only extract the
                result from the string.

                kind regards,

                Jos

                Comment

                • Nepomuk
                  Recognized Expert Specialist
                  • Aug 2007
                  • 3111

                  #9
                  Originally posted by JosAH
                  Sure, but the substring() method doesn't help a bit; it can only extract the result from the string.
                  Correct me if I'm wrong, but
                  Originally posted by Karthik Prasath
                  in this line i want to extract name of the student (ABINAYA N here) how can i do that?
                  suggests, that extracting the result from the string is part of the process. ^^

                  Greetings,
                  Nepomuk

                  Comment

                  • JosAH
                    Recognized Expert MVP
                    • Mar 2007
                    • 11453

                    #10
                    Originally posted by Nepomuk
                    Correct me if I'm wrong, but suggests, that extracting the result from the string is part of the process. ^^
                    Ah, so to questions like "I want to <fronobulax> my database and <mumble>
                    them and show the results to the user" you answer: System.out.prin tln() because
                    that method is part of the process. Big fun.

                    kind regards,

                    Jos

                    Comment

                    • Nepomuk
                      Recognized Expert Specialist
                      • Aug 2007
                      • 3111

                      #11
                      Originally posted by JosAH
                      Ah, so to questions like "I want to <fronobulax> my database and <mumble> them and show the results to the user" you answer: System.out.prin tln() because that method is part of the process. Big fun.
                      No, but answering: "You can use the System.out.prin tln() method for the actual showing-part." would be correct. And I just said: "You can work with the String.substrin g() method." ^^

                      As I said in my initial post, your solution is much more elegant and if possible should be preferred. But I thought, I'd offer a second option and let the OP think about the two.

                      Greetings,
                      Nepomuk

                      Comment

                      Working...