Split function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Reb

    Split function

    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.Spli t("name");

    Thanks
    Reb
  • Ravikanth[MVP]

    #2
    Split function

    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]


    [color=blue]
    >-----Original Message-----
    >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.Spli t("name");
    >
    >Thanks
    >Reb
    >.
    >[/color]

    Comment

    • Robert Jacobson

      #3
      Re: Split function

      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.Reg ularExpressions 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" <gbreb@yahoo.co m> wrote in message
      news:12a501c378 e6$f88df550$a50 1280a@phx.gbl.. .[color=blue]
      > 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.Spli t("name");
      >
      > Thanks
      > Reb[/color]


      Comment

      • Jay B. Harlow [MVP - Outlook]

        #4
        Re: Split function

        Reb,
        In addition to RegEx.Split as Robert suggests, you could use
        Microsoft.Visua lBasic.Strings. Split which splits based on a string.

        Alternatively you could create your own Split function using String.IndexOf
        & String.SubStrin g. 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

        "Reb" <gbreb@yahoo.co m> wrote in message
        news:12a501c378 e6$f88df550$a50 1280a@phx.gbl.. .[color=blue]
        > 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.Spli t("name");
        >
        > Thanks
        > Reb[/color]


        Comment

        Working...