Solved

a text file question again

Posted on 2001-09-13
8
130 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
 
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

759 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now