Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

C30N9

Members
  • Content count

    1331
  • Joined

  • Last visited

About C30N9

  • Rank
    Senior Member

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

Single Status Update

See all updates by C30N9

  1. 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

    1. fraggle

      fraggle

      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.

    2. C30N9

      C30N9

      Done it without using Pattern class. Not actually a regex, but it involves using the square brackets for multiple delimeters. I know it is useless, but I tried to make it without using Pattern. And yes, messy code is messy:

      code:
      Array

    3. Show next comments  3 more
×