hulken
asked on
a text file question again
I have a file that looks something like this.
each row starts with
"XXXXXX,
where XXXXX is some numbers.. What I like to do is modify this number.
a 0 should be added to the end, then some zeros should be added to the start of the XXX until XXX has length of 14 numbers.
for example the row
"989534,2345,banana""""
should be:
"00000009895340,2345,banan a""""
How can I do that?
each row starts with
"XXXXXX,
where XXXXX is some numbers.. What I like to do is modify this number.
a 0 should be added to the end, then some zeros should be added to the start of the XXX until XXX has length of 14 numbers.
for example the row
"989534,2345,banana""""
should be:
"00000009895340,2345,banan
How can I do that?
ASKER
It's aplain text file.. not unicoded.
just a moment...
hulken,
Try the following:
var
Output: string;
begin
// ...
Output:= Format('%.14d,%d,%s', [Num1, Num2, 'banana']);
// ...
end;
Try the following:
var
Output: string;
begin
// ...
Output:= Format('%.14d,%d,%s', [Num1, Num2, 'banana']);
// ...
end;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Could you give me an example?.. The Format %.14d, will it add one 0 to the end and then fill the number upp with 0000 in the beginning until it's 14 char ?
Hulken,
Sorry, I forgot the trailing '0' on the first number. In that case, the following will work:
Format('%.13d0,%d,%s', [Num1, Num2, 'banana']);
And yes, it will pad the front with zeros, insert the number (to fill the 13 characters), then add a trailing zero to the first number, followed by the second number and a string, like this:
Output:= Format('%.13d0,%d,%s', [123456789, 4321, 'banana']);
will cause Output to now contain the string: "00001234567890,4321,banan a"
Sorry, I forgot the trailing '0' on the first number. In that case, the following will work:
Format('%.13d0,%d,%s', [Num1, Num2, 'banana']);
And yes, it will pad the front with zeros, insert the number (to fill the 13 characters), then add a trailing zero to the first number, followed by the second number and a string, like this:
Output:= Format('%.13d0,%d,%s', [123456789, 4321, 'banana']);
will cause Output to now contain the string: "00001234567890,4321,banan
?
s := s + '0';
while length(s) < 14 do s := '0' + s;
s := s + '0';
while length(s) < 14 do s := '0' + s;
does it unicode file?
-----
Igor