Just to point out something that may seem like a detail: This will only work for integers in the range of a Int32. Therefore I think my proposal in post #6 is the way to go.
It really depends on how long the NVARCHAR is, as a few of the above (especially the ones that convert through IntXX) methods will not work for:
Code:
String s = "005780327584329067506780657065786378061754654532164953264952469215462934562914562194562149516249516294563219437859043758430587066748932647329814687194673219673294677438907385032758065763278963247982360675680570678407806473296472036454612945621946";
Something like this would:
Code:
String s = "0000058757843950000120465875468465874567456745674000004000".TrimStart( new Char[] { '0' } );
// s = "58757843950000120465875468465874567456745674000004000"
Last edited by rliq; September 15th, 2010 at 12:56 AM.
Rob
-
Ohhhhh.... Old McDonald was dyslexic, E O I O EEEEEEEEEE.......
Can someone give me the technical explanation why MySQL would pad "integers" with zeros if the datatype being applied to the value is varchar? (If that makes sense)
I had a comma separated value file with a column which contains records which were either 100% integer (304923094 for example), but some of the other records were hexadecimal / had characters (35GHQ153, for example). I imported the CSV file into MySQL using Navicat and specified that this column was to be datatype "Varchar 15". The hexadecimal values remained as they were in the CSV file, but the integer values got left padded with 0'sup to 15 total.
For example, RE122572 would import just like that, but 1258693 would import as 000000001258693
The left trim method works to fix this, but I want to understand exactly what's going on.
string a = "000012340";
string b = a.TrimStart('0');
I like things simple, any reason not to remove leading 0's this way?
That is the simplest; as far as I can tell.
Best Regards,
BioPhysEngr http://blog.biophysengr.net
--
All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.
Bookmarks