jmoreno
jmoreno

Reputation: 13571

What is the difference between string.split and strings.split

There are three functions for splitting a string in .net by a delimiter, String.Split and Strings.Split (from the Microsoft.VisualBasic dll) and of course Regex.Split which uses patterns.

What is the difference between String.Split and Strings.Split?

Upvotes: 0

Views: 367

Answers (1)

jmoreno
jmoreno

Reputation: 13571

The difference between the two is Strings.Split takes a string while String.Split takes an array (param array actually) of characters. Which splits on any of the characters in the array.

String.Split should be used when you need to split on one or more characters or when you know there will be a single delimiter, but don’t know which one it will be (comma, tab, or space). It is the most common and will cover most cases.

Strings.Split should be used when you need to split on a specific word.

Regex.Split should of course be used when you need to split on a pattern, not a fixed character or word. It can be used to split on a specific word, but will probably be slower than Strings.Split (but Strings.Split may be excluded by team policy as some people don’t like the MS.VisualBasic namespace)

Upvotes: 1

Related Questions