Where is the logic in:

Need to implement my own split method, and above is example what it should return, but can not see any logic.Code:`split("a?b?gf#e", "[?#]") returns a, b, ?, b, gf, #, e`

Printable View

- 01-27-2012, 09:54 PMdiamonddragonWhere's the logic?
Where is the logic in:

Code:`split("a?b?gf#e", "[?#]") returns a, b, ?, b, gf, #, e`

- 01-27-2012, 10:10 PMdoWhileRe: 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, 10:25 PMdiamonddragonRe: Where's the logic?
Is is just exercise, and can't see any logic in result.

- 01-27-2012, 10:28 PMdoWhileRe: Where's the logic?
Read the link - the logic is in the regular expression.

- 01-27-2012, 10:32 PMJosAHRe: Where's the logic?
On what are you calling the split( ... ) method? If I do this:

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,

Jos - 01-27-2012, 10:50 PMdiamonddragonRe: Where's the logic?
- 01-28-2012, 12:15 AMFubarableRe: 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

Code:`[a, b, gf, e]`

- 01-28-2012, 12:58 AMdiamonddragonRe: Where's the logic?
Need to implement own split method, such that

Code:`split("a?b?gf#e", "[?#]")`

Code:`[a, b, ?, b, gf, #, e]`

- 01-28-2012, 01:08 AMFubarableRe: 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, 01:36 AMdiamonddragonRe: Where's the logic?
Say:

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) {

}

}

- 01-28-2012, 03:35 AMFubarableRe: Where's the logic?
OK, well good luck with that.

- 01-28-2012, 05:16 AMdiamonddragonRe: Where's the logic?
Does it mean there's no logic?