Click here to Skip to main content
15,881,380 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
please tell me how to split a tring if s="hi (name), bye (name), you (alone)";

how to get 3 elements between tags

thanks in advance
Posted
Updated 13-Nov-11 18:09pm
v2

C#
string s = "hi,bye,you";
           string[] values = s.Split(',');



Will give you an array of strings containing each of your words.

Hope this helps
 
Share this answer
 
v2
Comments
thatraja 14-Nov-11 0:33am    
Simple & nice, 5!
Wayne Gaylard 14-Nov-11 0:36am    
Thanks man!
koolprasad2003 14-Nov-11 0:50am    
short and simple ans, +5
Wayne Gaylard 14-Nov-11 0:56am    
Thank you
Hi,

Try this:

C#
StringBuilder sb = new StringBuilder();
string s = "hi , bye , you";
var strSplit = s.Split(',');
for (int i = 0; i < strSplit.Count(); i++)
{
   sb.Append(strSplit[i]);
}
var result = sb.ToString();    // result...



Regards,
Al
 
Share this answer
 
v2
Hi,
I think this is the soln for your question.

C#
String lstrName = textBox1.Text;
            String[] lstrNameExtracted = lstrName.Split(',');
            foreach (string lstrSubName in lstrNameExtracted)
            {
                MessageBox.Show(lstrSubName.Substring(lstrSubName.IndexOf('(') + 1, lstrSubName.LastIndexOf(')') - lstrSubName.IndexOf('(')-1));
            }



Regards;
Madhusudan
 
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