Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
Solved

a text file question again

Posted on 2001-09-13
8
Medium Priority
?
139 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 200 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

647 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