Click here to Skip to main content
15,899,026 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
string[] Query = query.Split(';'); i am using this for for split string.i want code for how i split after semicolon.given code for split character in before semicolon.i want code for after semicolon.
Posted
Updated 9-Dec-13 21:23pm
v2
Comments
Sergey Alexandrovich Kryukov 10-Dec-13 2:42am    
Not clear. Isn't it .NET and C++/CLI? Then change your tags (click "Improve question").
Just read MSDN article on Split, what's the problem?
—SA
Nelek 10-Dec-13 3:18am    

If you want to split the word from ; and take the word after the ;
do like this

Eg: string query = "xxx;yyy"
string[] Query = query.Split(';');


Query [0] will be xxx
Query [1] will be yyy
 
Share this answer
 
You can't use string.Split to split after a character - it splits a string on a character: so it remove the split indicator, and returns two (or more) strings which do not contain the split character at all. Regular expressions also do the same thing, but can cope with a more complex matching pattern, so they won;t help you either.

There are three things you can do:
1) Write your own split method with does not remove the split character.
2) Use Split, and then add the split character back into each line afterwards.
3) Use String.Replace to add a "special character" after each semicolon, then split on that.

The second option would probably be the least efficient as the number of strings created is doubled.
 
Share this answer
 

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