Click here to Skip to main content
15,904,823 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI Experts,

I am reading a .CSV file using - testContextInstance.DataRow["UserKey1"].ToString();
But if UserKey1 data is 05453 then testContextInstance returns 5453.

The Prefix '0' is not read.

I wanted the data with prefix '0' to be returned by testContextInstance.
Do any any have any Idea?

Thanks
Rohit
Posted
Updated 7-Dec-11 18:15pm
v2
Comments
[no name] 8-Dec-11 0:15am    
EDIT: added formatting.

1 solution

Assuming that your output should allways show 5 digits, try PadLeft().

testContextInstance.DataRow["UserKey1"].ToString().PadLeft(5, '0')
 
Share this answer
 
Comments
Richard MacCutchan 9-Dec-11 7:49am    
Rather than deleting and reposting, you could always edit your original.
Michel [mjbohn] 9-Dec-11 8:09am    
Yes I know. I had some weird browser issue. After posting my solution, browser showed it twice. So I deleted one and both were gone :-D.
Reposting same text showed up as deleted so I gave up and posted a slightly modified text.
Sorry for confusion.
Richard MacCutchan 9-Dec-11 8:27am    
No problem, it's just that many people miss the "Improve" link and don't appreciate that questions and solutions can be easily modified. I guess you hit a server that was having a bad day.

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