Thread: Split string with string

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    3

    Split string with string

    I have text like this

    some text

    &&

    some text

    &&

    .....



    I want to split text, and this code works
    Code:
    values = s.Split('&');
    but it's not working if i place something like this
    Code:
    values = s.Split('&&');
    because it only takes char

    Thx for help

  2. #2
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,058
    A resolution based on my interpretation of your problem...

    Code:
    using System.Text.RegularExpressions;
    using System;
    
    class SplitItUpApp
    {
        static void Main(string[] args)
        {
            string input = "What&&we have&&here&&is a failure&&to&&communicate";
            Regex sp = new Regex(@"[&]+");
            foreach (string output in sp.Split(input))
            {
                Console.WriteLine(output);
            }
        }
     }

  3. #3
    Registered User
    Join Date
    Mar 2006
    Posts
    3
    Code:
    string str = "sometext&&watson&sons&&more text&&&&empty over there <--&&";
                string[] array = str.Split(new string[] { "&&" }, StringSplitOptions.None);
                foreach (string s in array)
                    Console.WriteLine(s);
    replay was posted before but it lokks like there was some database failure so it's deleted

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. char Handling, probably typical newbie stuff
    By Neolyth in forum C Programming
    Replies: 16
    Last Post: 06-21-2009, 04:05 AM
  2. split string function
    By paxmanchris in forum C Programming
    Replies: 6
    Last Post: 04-23-2007, 09:56 AM
  3. Custom String class gives problem with another prog.
    By I BLcK I in forum C++ Programming
    Replies: 1
    Last Post: 12-18-2006, 03:40 AM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM
  5. creating class, and linking files
    By JCK in forum C++ Programming
    Replies: 12
    Last Post: 12-08-2002, 02:45 PM