Results 1 to 9 of 9
Thread: check string inside string
- 07-06-2010, 09:31 PM #1
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 exampleTeaching myself java so that i can eventually join the industry! Started in June 2010
- 07-06-2010, 09:33 PM #2
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
- 07-06-2010, 09:43 PM #3
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
- 07-06-2010, 11:04 PM #4Member
- Join Date
- Aug 2009
- Rep Power
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.
- 07-07-2010, 04:40 AM #5
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.
- 07-07-2010, 04:43 AM #6
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?
- 07-07-2010, 04:59 AM #7Senior Member
- Join Date
- Feb 2010
- Waterford, Ireland
- Rep Power
I smell recursion in this thread :D
- 07-07-2010, 05:10 AM #8
- 07-07-2010, 12:52 PM #9
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.
thanksTeaching myself java so that i can eventually join the industry! Started in June 2010
- By j_kathiresan in forum New To JavaReplies: 1Last Post: 04-30-2010, 03:21 PM
- By Addez in forum New To JavaReplies: 4Last Post: 08-28-2009, 07:56 PM
- By McChill in forum New To JavaReplies: 5Last Post: 05-02-2009, 07:51 PM
- By mainy in forum JavaServer Pages (JSP) and JSTLReplies: 3Last Post: 03-01-2009, 11:08 AM
- By Heather in forum XMLReplies: 2Last Post: 03-28-2008, 06:21 PM