CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Split() in C#

  1. #1
    Join Date
    Jul 2003
    Posts
    28

    Split() in C#

    Hi,
    Is there any equavalent function to VB split() in C# .NET.
    In VB 6.0 we can use Split(String, string), splitting the string with multiple characters as string.
    Do we have any similar function in C#.

    Thanks
    Ramesh

  2. #2
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    263
    yes string.Split , eg:
    Code:
    string str = "test 123";
    string[] arr = str.Split(' '); // split the string's spaces
    
    //Note: you can also use the Regex class to split strings ( i find it faster )

  3. #3
    Join Date
    Jul 2003
    Posts
    28
    There is a difference here. In VB 6.0, we can specify string as parameter for Split() method. But string.split() in C# doesnt support it. Is there any way..

  4. #4
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    263
    you can use Regex , eg:
    Code:
    string str = "somelikestufflikethiswith the word like in it";
                foreach(string s in System.Text.RegularExpressions.Regex.Split(str , "like" ,System.Text.RegularExpressions.RegexOptions.IgnoreCase))
                {
                    Console.WriteLine(s);
                }
    string Signature = Censored;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured