Click here to Skip to main content
15,997,776 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,


I have a string as:
C#
name="Peter|Ronald|Garner|Simon|Liisha|Lori";


Now I want to to extract only name using array or array list and want name as :
Peter
Ronald
Garner
Liisha
Lori



Thanks
Mohammad Wasif
Posted
Updated 28-Dec-11 18:36pm
v2

Quote:
Mohd Wasif - 5 hrs ago
I want output as:

Peter
Ronald
Garner
Liisha
Lori


here is the code for your output

C#
string name = "Peter|Ronald|Garner|Simon|Liisha|Lori";
foreach (string s in name.Split('|'))
    Console.WriteLine(s);
 
Share this answer
 
Dear Wasif,

I gave you the 85% solution i.e. more than half of your work is done by me now if you don't want to do something yourself :-X then this is not the site for you :)

still apply '/n' after each word to have the display you want.

Please Mark this as your answer if it helps you out.

Cheers
 
Share this answer
 
Dear Wasif,

For this you have to define a string array like this:-

string[] strArray= name.Split('|');


This thing will put all your names in an array.

Don't forget to mark this as your answer if it helps you out.

Thanks
 
Share this answer
 
Comments
Mohd Wasif 29-Dec-11 1:02am    
I want output as:

Peter
Ronald
Garner
Liisha
Lori
Amir Mahfoozi 29-Dec-11 3:16am    
So use a foreach and write them on the console. What is the problem after converting it to a list ?
Hi,

See this sample:

C#
string name = "Peter|Ronald|Garner|Simon|Liisha|Lori";
var myArray = name.Split('|');


Regards,
 
Share this answer
 
Try out this

C#
string name = "Peter|Ronald|Garner|Simon|Liisha|Lori";
        string[] str = name.Split(new char[]{'|'});



Hope this will help :)

Thanks
Vinod
 
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