Click here to Skip to main content
15,905,427 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi

How to split this string

1!=2

In winform

I need 1 and 2 separate..
Posted
Updated 18-Jun-13 21:25pm
v2

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);


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
 
C#
string str = "1!=2";
string[] strArr = str.Split(new string[] { "!=" }, StringSplitOptions.None);


fixed the quotes.
 
Share this answer
 
v3
Comments
rahuls1 19-Jun-13 3:10am    
i will not work it give error to may character....
Answer updated, try now.
 
Share this answer
 
Comments
rahuls1 19-Jun-13 3:15am    
there every ting is seprated by single operator her it is two operator please give working solution
If you have value as like same format then you can use given code:
C#
string str = "1!=2";
string[] s = str.Replace('!', ',').Replace('=', ' ').Split(',');   


I hope its helping to you
 
Share this answer
 
v4
C#
string[] myArray = mystring.Split(new string[] {"!="});
 
Share this answer
 
Comments
StianSandberg 19-Jun-13 6:13am    
correct solution, but why do you post the exact same answer as Tadit Dash did 3 hours ago??
muneebalikiyani 19-Jun-13 6:21am    
@AlluvialDeposit when i answered the question , no one's solution has been marked as answered so that why i answered without reviewing all answers

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