Page 1 of 1

String.split

PostPosted: Sun May 02, 2010 5:01 am
by Charles
Many times I just want to write:
someString.split(',')

But out of the box, the .NET library offers splitting on characters (which would be: c','), arrays of characters or arrays of strings (see docs). I get tired of "fixing" the call, so I have added some simple extension methods to enable the split on a string. Nothing fancy; just another convenience.

def split(separator as String) as String[]
def split(separator as String, count as int) as String[]
def split(separator as String, options as StringSplitOptions) as String[]
def split(separator as String, count as int, options as StringSplitOptions) as String[]

While I normally prefer returning a List<of String> over an array, I went with the array to match the existing API. You can always slap a ".toList" on an array if that's what you need.