Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to get output as '1234567' when using string builder in C#.NET.
Those reocrds I pass from data table.

Thanks in advance...

[Edit] Removed shouting. [Edit]
Posted
Updated 10-Sep-12 0:07am
v2

AppendFormat method should do:

C#
StringBuilder s = new StringBuilder();

s.AppendFormat("'{0}'", myData);



Cheers
 
Share this answer
 
v2
Comments
Kuthuparakkal 10-Sep-12 6:11am    
very nice, my 5+
string.Format() can also help:

C#
string output = string.Format("'{0}'", data);
 
Share this answer
 
C#
string s = "1,2,3"; string replaced = "'"+s.Replace(",", "','")+"'"; 

or


string s = "123"; string replaced = "'"+s.Replace("", "'")+"'"; 


check if the above help , still not sure what exactly r u asking for
 
Share this answer
 
Comments
Kuthuparakkal 10-Sep-12 6:10am    
absolutely weird
Rickin Kane 10-Sep-12 21:27pm    
sorry buddy , really weird
Mario Majčica 10-Sep-12 6:18am    
A performance and readability disaster! :)
Rickin Kane 10-Sep-12 21:26pm    
hey mario , thanks for highlighting the error never realise that the question was for Datatable and string builder related , thought it to be just string conversion , apologies friends

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