Results 1 to 12 of 12
Thread: Where's the logic?
- 01-27-2012, 08:54 PM #1
Senior Member
- Join Date
- Jan 2012
- Posts
- 210
- Rep Power
- 2
- 01-27-2012, 09:10 PM #2
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,608
- Rep Power
- 5
Re: Where's the logic?
Since split is based upon a regular expression, are you referring to the logic of Regular Expressions?
See Lesson: Regular Expressions (The Java™ Tutorials > Essential Classes)
But why reinvent the wheel?
- 01-27-2012, 09:25 PM #3
Senior Member
- Join Date
- Jan 2012
- Posts
- 210
- Rep Power
- 2
Re: Where's the logic?
Is is just exercise, and can't see any logic in result.
- 01-27-2012, 09:28 PM #4
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,608
- Rep Power
- 5
Re: Where's the logic?
Read the link - the logic is in the regular expression.
- 01-27-2012, 09:32 PM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,406
- Blog Entries
- 7
- Rep Power
- 17
Re: Where's the logic?
On what are you calling the split( ... ) method? If I do this:
... it doesn't give me any surprise.Java Code:import java.util.Arrays; public class T { public static void main(String[] args) { String[] r= "a?b?gf#e".split("[?#]"); System.out.println(Arrays.toString(r)); } }
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 01-27-2012, 09:50 PM #6
Senior Member
- Join Date
- Jan 2012
- Posts
- 210
- Rep Power
- 2
-
Re: Where's the logic?
Can you explain what you're saying here, because you've lost me completely. From what Jos's code looks like, the output should be
Perhaps you need to spell out more clearly just what you're trying to do including what part of your bit above is supposed to change -- your result or your code. If your code, I don't see how you can get the output you expect via regex (or any means as I don't see how the output is tied logically to the String entered).Java Code:[a, b, gf, e]
Last edited by Fubarable; 01-27-2012 at 11:22 PM.
- 01-27-2012, 11:58 PM #8
Senior Member
- Join Date
- Jan 2012
- Posts
- 210
- Rep Power
- 2
Re: Where's the logic?
Need to implement own split method, such that
will return exactly:Java Code:split("a?b?gf#e", "[?#]")
That is requested, and my question is where is the logic in that output?Java Code:[a, b, ?, b, gf, #, e]
-
Re: Where's the logic?
But again, what are the constants and what are the variables?
For example, are the constants the input String "a?b?gf#e" and the output [a, b, ?, b, gf, #, e]? Is this unchangeable? And is the thing you must change the regex String used in the Split? The "[?#]" part?
And what do you mean "implement own split method"? Do you mean you need to write a method that replaces String's split method or that you must use String's split method to achieve your result?
Again, you're still leaving a lot unsaid. Please assume that we can't read your mind.
- 01-28-2012, 12:36 AM #10
Senior Member
- Join Date
- Jan 2012
- Posts
- 210
- Rep Power
- 2
Re: Where's the logic?
Say:
Java Code:public class StringSplitMethod { public static void main(String[] args) { String[] r; r = split("a?a#b?gf#e", "?"); System.out.println(Arrays.toString(r)); r = split("a?a#b?gf#e", "[?#]"); System.out.println(Arrays.toString(r)); } public static String[] split(String s, String regex) { } }
-
Re: Where's the logic?
OK, well good luck with that.
- 01-28-2012, 04:16 AM #12
Senior Member
- Join Date
- Jan 2012
- Posts
- 210
- Rep Power
- 2
Similar Threads
-
Logic Help
By Barbados in forum New To JavaReplies: 6Last Post: 01-22-2012, 11:24 PM -
Need help in logic
By nn12 in forum New To JavaReplies: 3Last Post: 03-23-2011, 06:44 PM -
Need help on logic
By nn12 in forum New To JavaReplies: 6Last Post: 03-10-2011, 11:06 AM -
need a logic for this
By rajivjoshi in forum New To JavaReplies: 4Last Post: 06-12-2010, 02:18 PM -
Cant get the logic right
By jermaindefoe in forum New To JavaReplies: 4Last Post: 03-11-2008, 12:22 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks