Split function

  • Thread starter Thread starter Reb
  • Start date Start date
R

Reb

Hi,

I could split only by a character. How do i split by a
string.
How can i do something like this.
e.g., somestring.Split("name");

Thanks
Reb
 
Hi

use Split overloaded method.

public string[] Split(
params char[] separator
);

Parameter is An array of Unicode characters that delimit
the substrings in this instance, an empty array
containing no delimiters, or a null reference (Nothing in
Visual Basic).

HTH

Ravikanth[MVP]
 
The split function just examines individual characters to determine whether
they're delimiters.

If you want to "split" by an entire string, like splitting "xyzzy name
foobar" into "xyzzy" and "foobar," you'll need to use regular expressions
(in the System.Text.RegularExpressions namespace.) The overloaded Split
function will check for individual character delimiters (e.g., "f", "o" "b"
"a" or "r") but not entire strings. Alternatively, you could roll your own
function.
 
Reb,
In addition to RegEx.Split as Robert suggests, you could use
Microsoft.VisualBasic.Strings.Split which splits based on a string.

Alternatively you could create your own Split function using String.IndexOf
& String.SubString. Or use String.Replace to replace each delimiter string
with a distinct char ('\0' per haps), then use String.Split on this char.

Hope this helps
Jay
 
Back
Top