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

I have an excel file and I am splitting cell content based on special charectors as shown below:

dt =new DataTable();

dt.Columns.Add("Name");

dt.Columns.Add("Age");

dt.Columns.Add("Skills");

dt.Columns.Add("counts");

string name = rdr[0].ToString();

string age = rdr[1].ToString();

char[] s = new char[1] { ';' };

char[] k=new char[1] {'@'};

string[] skills = rdr[2].ToString().Split(s);

string[] counts = rdr[3].ToString().Split(k);

(ie) If i have below table

Name kk

Age 31

Skills .net;sqlserver;oracle

counts 1@2@3@


output will be :

kk 31 .net 1

sql 2

oracle 3


I am successfull in achieveing above output.

Required Output1:

if you have 1@# 2@# 3@# in counts column instead of 1@2@3@,the how do i split below expression?

char[] k=new char[1] {'@'};

Required Output2:

how to split expression (char[] k=new char[1] {'@'};---> if i have both @# and @ (ie) like: 1@# 2@ 3@ in 'counts' column.

here also i want output as :


1

2

3



Hope I am clear.Please help me in sorting this issue.



Thanks,

Kranthi
Posted
Comments
[no name] 14-Apr-14 17:05pm    
You can split using multiple characters....

1 solution

Not quite clear, but perhaps you'll solve your problem if you add the option System.StringSplitOptions.RemoveEmptyEntries:
http://msdn.microsoft.com/en-us/library/ms131448.aspx[^],
http://msdn.microsoft.com/en-us/library/system.stringsplitoptions%28v=vs.110%29.aspx[^].

—SA
 
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