Solved

a text file question again

Posted on 2001-09-13
8
133 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

861 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