1 2 Previous Next 23 Replies Latest reply: Mar 12, 2007 11:32 AM by 807599 RSS

    string mstching. (or something along that line)

      Ok, im playing this game and im writting this program to help me. The game is a virtual hacking game.

      U have logs and when people hack u u can get their ip.

      well ips are as follows.

      a set of four groups of numbers. (n.n.n.n)
      and none of the groups are less than one and greater than 3 digits.
      alo all digits in a group as one number are not greater than 255. ( = not true)

      now how would i go about prashing a textarea for thoes ips?

      Message was edited by:
        • 1. Re: string mstching.
          Use the split method and split on a period to get an array of Strings

          1st test - make sure there are four elements in the array.

          2nd test - make sure all elements have a length between 1 and 3 inclusive.

          3rd test - make sure all elements are numbers.

          4th test - make sure all numbers are >= 1 and <= 255
          • 2. Re: string mstching.
            ok thanxs for that. M bigger problem wich i forgot to post was how do i get the aryas heres an example of the log:
            12-03-2007 02:59  [] installed virus OpenRelay-backdoor.vspam on [localhost]
            12-03-2007 02:58 [] uploaded file OpenRelay-backdoor.vspam(0.003 Gb) to [localhost]
            12-03-2007 02:56 admin logged in from []
            12-03-2007 02:55 admin logged in from [131.37.190.!]
            12-03-2007 02:55 [] downloaded file Antivirus beta program.av(0.014 Gb) from [localhost]
            12-03-2007 02:53 [] uploaded file Marketing.mailer(0.005 Gb) to [localhost]
            how would i go about getting the aryas from that to check?
            • 3. Re: string mstching.
              What are "aryas"?

              Spelling error?
              • 4. Re: string mstching.
                arrays, yes im sorry.
                • 5. Re: string mstching.
                  You know what's amazing? By reading the API I found that the String class has a a method called substring.
                  • 6. Re: string mstching.
                    ok, i read the substring commsnd, but the thing is thats and example, their can be hundreds of lines in a log. I have to find a string wich matchs the critirea i specified nd strip it.

                    the substring if i understand it would only work if it was a set index.
                    • 7. Re: string mstching.
                      Does each ip address appear on a different line?

                      Yes, then take a single line from the log, use substring to get the ip address and then go back to reply #1.

                      In future please inform us of the size of the spoon you require.
                      • 8. Re: string mstching.
                        substring i will state again will not work. I aprently have not set the right size spoon.
                        U must set a specific index with sub string, correct? Well the ip could appear on index 10 or 20 or 5, dependig on what the person does and what time of day it is.
                        • 9. Re: string mstching.
                          Open wide.
                          String text = "Once upon a time [I lack the ability to think for myself] in a galaxy far far away";
                          System.out.println(text.substring(text.indexOf("[") + 1, text.indexOf("]")));
                          • 10. Re: string mstching.
                            could this be done with a regular expression?
                            how do u belive i would set it up?

                            we posted simatamiously.

                            Message was edited by:
                            • 11. Re: string mstching.
                              thanks for that cod, but do u think the hole thig would be easier using regular expessions?
                              • 12. Re: string mstching.
                                No offense dude but you appear to be struggling with this. I highly doubt you would understand how to do it with regex.
                                • 13. Re: string mstching.
                                  Ok, so i have made a buetifull little form with an action listener and have pluged the folllowing into the action listener.
                                            final String newL = "\n";
                                            String textValue = textArea1.getText();
                                            textArea2.append((textValue.substring(textValue.indexOf("[") + 1, textValue.indexOf("]"))) + newL);
                                  and i plug in the above log into textarea1 and then press the button and all i get back is one ip. RIght now im just trying to get it to print out everything between the [] later i will work on the symtamax checking
                                  • 14. Re: string mstching.
                                    So you have it working for one ip/line. Now you want it to do it for all ips/lines. How do you do the same thing over and over again?
                                    1 2 Previous Next