Solved

a text file question again

Posted on 2001-09-13
8
132 Views
Last Modified: 2010-04-06
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,banana""""

How can I do that?
0
Comment
Question by:hulken
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 9

Expert Comment

by:ITugay
ID: 6479275
Hi hulken,
does it unicode file?

-----
Igor
0
 

Author Comment

by:hulken
ID: 6479277
It's aplain  text file.. not unicoded.

0
 
LVL 9

Expert Comment

by:ITugay
ID: 6479281
just a moment...
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 1

Expert Comment

by:malsoft
ID: 6479288
hulken,

Try the following:

var
 Output: string;
begin
  // ...
  Output:= Format('%.14d,%d,%s', [Num1, Num2, 'banana']);
  // ...
end;
0
 
LVL 9

Accepted Solution

by:
ITugay earned 50 total points
ID: 6479303
Hi hulken,

function ConvertString(S: String): String;
var
  I: Integer;
begin
  I := Pos(',', S);
  Insert('0', S, I);
  while I <= 14 do
  begin
    Insert('0', S, 2);
    inc(I);
  end;
  Result := S;
end;

var
  S: TStrings;
  I: Integer;
begin
  S := TStringList.Create;
  S.LoadFromFile('filename');
  for I := 0 to S.Count-1 do
    S[I] := ConvertString(S[I]);
  S.SaveToFile('filename');
end;

-----
Igor.  
0
 

Author Comment

by:hulken
ID: 6479305
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 ?
0
 
LVL 1

Expert Comment

by:malsoft
ID: 6479336
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,banana"
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6479350
?

s := s + '0';
while length(s) < 14 do s := '0' + s;
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question