Delphi manipulate help

Good Day

I have a string as follows

67           225,231.37DB                                  7,758.41

I want to read each character in the string, if I see that there are more then 15 spaces in the string then I want to fill it with 0.00.

example output should then be

67           225,231.37DB               0.00               7,758.41

Can someone please help me

henryreynoldsAsked:
Who is Participating?
 
ThommyConnect With a Mentor Commented:
This should work...
function checkstr(s:string):string;
var
  i,CountSpaces:integer;
begin
  i:=1;
  CountSpaces:=0;

  while i<=length(s) do begin
    if s[i]=' ' then inc(CountSpaces) else CountSpaces:=0;

    if CountSpaces=16 then begin
      Insert('0.00',s,i-1);
      CountSpaces:=0;
    end;

    inc(i);
  end;

  result:=s;
end;

Open in new window

0
 
henryreynoldsAuthor Commented:
Thanx thommy it work 100%
0
 
ThommyCommented:
You can also use POS(..) function...
function CheckStrPos(s:string):string;
var
  p:integer;
begin

  Repeat
    p:=pos(StringOfChar(' ',16),s);
    if p>0 then insert('0.00',s,p+14);
  until p=0;

  result:=s;
end;

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.