Solved

a text file question again

Posted on 2001-09-13
8
134 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to call a form that is in a DLL  from an application? 13 87
Dev Express grid collapse 2 47
LAN or WAN ? 11 106
Performance of SQL statement 37 137
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

726 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