Click here to Skip to main content
15,887,175 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to split a string in asp.net using c#???
Posted
Comments
lukeer 31-May-12 4:06am    
For future questions, please think of a more descriptive heading. (As mentioned here[^])

You can use the overload of String.Split[^] which takes a StringSplitOptions:
C#
string[] bits = text.Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries);

To avoid creating a char array on each call, you can use:
C#
private static readonly char[] SplitSeparators = {' '};

...

string[] bits = text.Split(SplitSeparators,
                           StringSplitOptions.RemoveEmptyEntries);
 
Share this answer
 
C#
string inStr = "123,456,789";
string[] parts = inStr.Split(',');
Console.WriteLine(parts[0]);
Console.WriteLine(parts[1]);
Console.WriteLine(parts[2]);
 
Share this answer
 
VB
// 1.public string[] Split(params char[] separator);

// 2.public string[] Split(char[] separator, int count);

// 3.public string[] Split(char[] separator, StringSplitOptions options);

// 4.public string[] Split(string[] separator, StringSplitOptions options);

// 5.public string[] Split(char[] separator, int count, StringSplitOptions options);

// 6.public string[] Split(string[] separator, int count, StringSplitOptions op



For more details, have look: http://www.ezineasp.net/post/ASP-Net-C-sharp-Split-String-Function.aspx[^]

Splitting string in C#[^]
 
Share this answer
 
1.
ASP.NET
<asp:label id="lblprodname" runat="server" text="<%# Eval("itemname").ToString().Substring(0, 25)+ "..." %>" xmlns:asp="#unknown">


2.
C#
str_pt = str_pt.Remove(0, 2);   // it remove two character from left side


3.
C#
if (dprice.IndexOf("-") > 0)
                   {
                       string[] str = dprice.Split('-');
                       if (str.Length > 0)
                           sql = str[0] + "," + str[1] + "," + Session["currency"];
                   }
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900