Forums

String.split

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

String.split

Postby Charles » Sun May 02, 2010 5:01 am

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.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Return to Discussion

Who is online

Users browsing this forum: No registered users and 27 guests