-
Content count
1331 -
Joined
-
Last visited
Single Status Update
-
I'm supposed to write a method that acts like java.lang.String.split, except that this new method returns a String array including the delimeters. For example:
split("Java#HTML#Cpp", "#") would return "Java", "#", "HTML", "#" and "Cpp" in an array. I already done the hard part, which returns the array correctly. However, I don't how to make it work with regular expressions, such as:
split("Java#HTML$Cpp%Python", "[#$%]"). It should return:
"Java", "#", "HTML", "$", "Cpp", "%", "Python".
Any ideas?
Here is my code BTW:code:
Array-
Instant fail because "String regex" is not interpreted as a regex. You need to either compile that argument to a java.util.regex.Pattern, or (better, if possible), change the type of that argument from String to java.util.regex.Pattern.
Read up on what a regular expression is if you don't know already. You're supposed to split on a pattern, not a fixed string. Don't try to write your own regex parser.
Final point, you should never need to call new String(). Strings are immutable in Java. - Show next comments 3 more
-