Results 1 to 9 of 9
  1. #1
    alacn's Avatar
    alacn is offline Senior Member
    Join Date
    Jun 2010
    Location
    UK. near London
    Posts
    118
    Rep Power
    0

    Default check string inside string

    hey ive got a program which checks winning combination inside a main string.

    so for example if the main string is 12376 and i check the the winning combination of "123" i can find it using the string.indexof method however sometimes its not that simple and the main string might be 12763 (as an example)

    is there a method or way inwhich i can check to see if a string contains the winning combination even when it may be jumbled up like above?

    id also like to mention that 123 isnt the only winning combination im checking, im just using it as an example
    Teaching myself java so that i can eventually join the industry! Started in June 2010

  2. #2
    alacn's Avatar
    alacn is offline Senior Member
    Join Date
    Jun 2010
    Location
    UK. near London
    Posts
    118
    Rep Power
    0

    Default

    i know i could prolly do a variation of string.indexof whereby i check to see if 1 is in there and 2 is in there and 3 and then return a true, but is there another way?
    just checking to see if there is a more pro way of doing it tbh
    Last edited by alacn; 07-06-2010 at 09:35 PM.
    Teaching myself java so that i can eventually join the industry! Started in June 2010

  3. #3
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    6

    Default

    You'd have to write that yourself. What happens if main is "12345" and wc is "111"? Is that a match or not?

    Also consider whether it's worth to have a weird regex or 10 lines of code which are understandable.
    Last edited by PhHein; 07-06-2010 at 09:50 PM.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  4. #4
    senorbum is offline Member
    Join Date
    Aug 2009
    Posts
    76
    Rep Power
    0

    Default

    Just write the method yourself. There isn't a method as part of the java libraries that will get you what you need.

    Also, don't use a regex. Keep it Simple. Reserve regex's for things that can't be done with a few lines of code.

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    I don't think it's a bad idea to use a regex for identify a valid string. But for the processing the selected one, use of regular expressions is not a good idea.

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    I've one question for you. Did you choose a string as a winning string without considering the pattern of containing the validate string (123 as your example) within the original string?

  7. #7
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    I smell recursion in this thread :D

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  9. #9
    alacn's Avatar
    alacn is offline Senior Member
    Join Date
    Jun 2010
    Location
    UK. near London
    Posts
    118
    Rep Power
    0

    Default

    no pattern needs to be present, only the individual numbers need to be present.

    Ok i will write this method myself, and i will look into this "regex" for further studying.

    I will post a new thread soon showing all my code that i have wrote for a GUI tic tac toe game. Im quite happy with it, however id like some advice on how to the code can be made more efficient and if im using ObjectOrientated properly.

    thanks
    Teaching myself java so that i can eventually join the industry! Started in June 2010

Similar Threads

  1. Replies: 1
    Last Post: 04-30-2010, 03:21 PM
  2. Replies: 4
    Last Post: 08-28-2009, 07:56 PM
  3. check if String is an integer?
    By McChill in forum New To Java
    Replies: 5
    Last Post: 05-02-2009, 07:51 PM
  4. [SOLVED] Getting the value inside a SQL Query into a String.
    By mainy in forum JavaServer Pages (JSP) and JSTL
    Replies: 3
    Last Post: 03-01-2009, 10:08 AM
  5. string inside of a xml
    By Heather in forum XML
    Replies: 2
    Last Post: 03-28-2008, 05:21 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •