2 Replies Latest reply: May 14, 2013 1:57 AM by gimbal2 RSS

    Separating letters in txt file to two different strings

    1008701
      I have a text file that has the results of rock paper scissors game.
      R P
      S R
      P P

      I need to have the first letter in each line assigned to player1 and the second letter in each line assigned to player 2.
      I have no clue where to start. I have the file input correct. It is reading the file and I can separate ints from strings. I just don't know how to separate the strings.
        • 1. Re: Separating letters in txt file to two different strings
          1008701
          If i had to guess, it would involve putting a ++ somewhere.
          • 2. Re: Separating letters in txt file to two different strings
            gimbal2
            1005698 wrote:
            If i had to guess, it would involve putting a ++ somewhere.
            But you shouldn't be guessing, you should be knowing. You say you want to SEPARATE a String. So what is stopping you from typing "java separate string" into Google? You get some interesting results I can tell you.

            When I was learning and I needed to do something very specific my first stop was always the javadocs. In this case you want to separate (or "split") a String, so a logical place to look would be the javadoc for the String class. Easy to get to, just type "java 7 String" into google and off you go.

            http://docs.oracle.com/javase/7/docs/api/java/lang/String.html

            And then its a question of scanning the available method names to see one that might fit your needs. Don't understand how to properly use it? Google it! The whole world uses Java, you have a rich history of examples and articles at your disposal that I certainly did not have when I started out. Use it, please.