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

In my application I am taking the values from the database like 'd1234','d1234','d123', I want to split this values and I want to save the values like

'd1234',
'd1234',
'd1234',
'd1234',

Can any one help me to solve this issue. I want split the data And I want to make the data in the above given format

Thanks in Advance
Posted
Updated 10-May-12 23:09pm
v2
Comments
Sebastian T Xavier 11-May-12 3:05am    
do you want to split the string or want to get the result data in this desired format?
Maciej Los 11-May-12 5:33am    
You should be more specific... What kind of database: Access, SQL Server, other? Do you know how to read data from a database? What have you done so far?

Hello there,

C#
string yourStringFromDB = "your,string,from,db";
//
// Split string on the base of ",". This will separate all the words.
//
string[] words = yourStringFromDB.Split( new Char[] { ',' }, StringSplitOptions.RemoveEmptyEntries );
foreach (string word in words)
{
    Console.WriteLine(word);
}


Hope this helps you out,

Regards,
Umer
 
Share this answer
 
v6
Comments
Maciej Los 11-May-12 5:35am    
Check out your example and correct it... ;)
Umer Aziz Malik 11-May-12 5:54am    
ummm can you please point out the mistake?
Morgs Morgan 11-May-12 5:58am    
I added the StringSplitOptions.RemoveEmptyEntries to help get read of empty entries as seen in the example poster has a , at the end which end-up printing an empty string
Umer Aziz Malik 11-May-12 5:59am    
Good work :)
what u want to do with the string from database now make it clear ....
 
Share this answer
 
Comments
Dhanamanikandan 11-May-12 3:22am    
@Dharan.. Plz post your questions by click the 'Have a question or comment?' link.. Don't Post in Solution textarea.

Thanks

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