Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I have a string where the values are pipe separated.

Eg-
string val = "Value1|Value2|Value3|Value4|Value5|Value6|Value7|Value8|Value9|Value10":


I have to retrieve Value7 from the string.How to go about it?

Bye
Posted
Comments
VJ Reddy 27-Apr-12 2:34am    
Thank you for accepting the solution.

I think the Split method of string class can be used as below
C#
string val = "Value1|Value2|Value3|Value4|Value5|Value6|Value7|Value8|Value9|Value10";
string[] vals = val.Split(new char[]{'|'}, StringSplitOptions.RemoveEmptyEntries);
string val7 = vals[6];
Console.WriteLine (val7);
 
Share this answer
 
Comments
member60 28-Apr-12 0:33am    
My 5!
VJ Reddy 28-Apr-12 0:40am    
Thank you, member60.
Hi,

If val is in this format you can use:

C#
string val = "Value1|Value2|Value3|Value4|Value5|Value6|Value7|Value8|Value9|Value10";
string[] valarr=val.Split('|');
string SeventhVal=valarr[6];
 
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