parsing a character of numbers that begins with 0 and keeping the initial zeroHi,
I want to make a vector of values that come from a column in a datatable. Some of those values start with the number zero. When I use the parse command it truncates the zero from the beginning of the number. The column is defined as a character column. The script I am using is eval(parse(column(DTI, "bar_pen")[i]))); How can I do this and keep my initial zeros?
Thanks,
Tova
Re: parsing a character of numbers that begins with 0 and keeping the initial zerothanks, that is a much neater solution than the one i found...
Re: parsing a character of numbers that begins with 0 and keeping the initial zerodt = New Table( "Untitled",
Add Rows( 3 ),
New Column( "Bar_Pen", Character, Set Values( {"0001", "9999", "0900"} ) )
);
list = dt:Bar_pen << getvalues;
show(list); // {"0001", "9999", "0900"};
v = dt:Bar_Pen[3];
show(v, parse(v), char(parse(v))); // "0900", 900, "900"
You might not need to do the parse that converts the character data to code (which is just a number, most likely.) Then you don't need to eval the parsed code, then you don't need to convert the evaluated answer (a number) back to a string. If the values need cleaning up because of data entry errors, the eval/parse may seem to be working but will fail if a mischievous user puts bad code in the table.
Re: parsing a character of numbers that begins with 0 and keeping the initial zerothis is what worked for me in the end:
Repeat("0", 4 - length(char(eval(parse(column(DTI, "Bar_Pen")[i]))))) || char(eval(parse(column(DTI, "Bar_Pen")[i])));