3 Replies Latest reply: Nov 1, 2010 6:58 AM by YoungWinston RSS

    String manipulation. ...? Help needed. ..!!

    809644
      Hi,

      I wanted to format string as follows:

      Input string:
      staffnum|role|name|lastname

      12345|role1|abc|pqr
      12345|role2|abc|pqr


      Required Output String:

      12345|role1,role2|abc|pqr

      i.e. I wanted to separate role field by comma for same staff number and wanted to remove second row of same staff number.

      please help.
        • 1. Re: String manipulation. ...? Help needed. ..!!
          793415
          What is your question?

          This is not a code generation service, so it helps to:
          <li> Show the best attempt you have made so far.
          <li> Explain exactly how the required output differs from the actual output of your code.
          <li> Ask a specific question.

          Also, please fix those sticky '.' & '!' keys.

          Handy reading would be How To Ask Questions The Smart Way (http://catb.org/esr/faqs/smart-questions.html).
          • 2. Re: String manipulation. ...? Help needed. ..!!
            797060
            I'm going to answer this, although I shouldn't - sometimes all you need is to just know the name of a function that is really easy for someone to tell you rather than spend hours looking for it (or making your own implementation that is rubbish and takes ages)

            use String.split()

            searching for "splitting a string java" on google produces, at the first result, http://www.rgagnon.com/javadetails/java-0438.html describing exactly what you need. The person above asked you to "give it a go" to produce a better question because if you had, you would have most likely found the answer in the time it took me to write this answer.

            Edited by: 794057 on 01-Nov-2010 03:57
            • 3. Re: String manipulation. ...? Help needed. ..!!
              YoungWinston
              806641 wrote:
              i.e. I wanted to separate role field by comma for same staff number and wanted to remove second row of same staff number.
              Another suggestion: Step back from the details and work out what your problem is. Java is an object-oriented language, and it might be better to ask yourself if there's a class you could write that might help (eg, StaffMember?).

              Winston