C# .NET - how t split string with br /? - Asked By deepi singh on 02-Jan-12 04:38 AM

string[] EmailToAddress = ToAddresses.Split('<br />');

iam getting error as too many characters in character literal?

smr replied to deepi singh on 02-Jan-12 04:41 AM
hi

refer to this example

class TestStringSplit
{
  static void Main()
  {
    char[] delimiterChars = { ' ', ',', '.', ':', '\t' };
  
    string text = "one\ttwo three:four,five six seven";
    System.Console.WriteLine("Original text: '{0}'", text);
  
    string[] words = text.Split(delimiterChars);
    System.Console.WriteLine("{0} words in text:", words.Length);
  
    foreach (string s in words)
    {
      System.Console.WriteLine(s);
    }
  
    // Keep the console window open in debug mode.
    System.Console.WriteLine("Press any key to exit.");
    System.Console.ReadKey();
  }
}
/* Output:
  Original text: 'one   two three:four,five six seven'
  7 words in text:
  one
  two
  three
  four
  five
  six
  seven
 */
Chintan Vaghela replied to deepi singh on 02-Jan-12 06:11 AM

Hello,

 

Try as follows

 

string str = "hai<br/>how<br/>Are<br/>you";

        string[] delim = { "<br/>" };

        string[] spltd = str.Split(delim, StringSplitOptions.None);

        for (int i = 0; i < spltd.Length; i++)

        {

          MessageBox.Show(spltd[i]);

        }

 

Hope this is helpful !

Thanks

 

 

 

 

 

Suchit shah replied to deepi singh on 02-Jan-12 06:19 AM
Just do it like below one

string[] EmailToAddress = Regex.Split(ToAddresses,"<br />");


this will do your task


Chintan Vaghela replied to deepi singh on 02-Jan-12 06:49 AM

Hello,

  string stTemp = "ABC<br/>XYZ<br/>PQR";

 

        string[] stDeli = { "<br/>" };

 

        string[] stFinalResult = stTemp.Split(stDeli, StringSplitOptions.None);

 

Hope this is helpful !

Thanks

 

 

 

 

 

Chintan Vaghela replied to deepi singh on 02-Jan-12 07:35 AM

Hello,

  string stTemp = "ABC<br/>XYZ<br/>PQR";

 

        string[] stDeli = { "<br/>" };

 

        string[] stFinalResult = stTemp.Split(stDeli, StringSplitOptions.None);

 

Hope this is helpful !

Thanks

 

 

 

 

 

kalpana aparnathi replied to deepi singh on 02-Jan-12 02:32 PM
hi,


Try
this:
string[] readlines2 = TextBox1.Text.Split('\r');
for (int i = 0; i < readlines2.GetUpperBound(0); i++)
  Response.Write(readlines2[i] + "<br />");