• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 195
  • Last Modified:

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

0
henryreynolds
Asked:
henryreynolds
  • 2
1 Solution
 
ThommyCommented:
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

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.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now