Forum > Beginners

Trouble with DelSpace1 (Solved)

<< < (2/5) > >>

KodeZwerg:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function FilterAscii(const AString: string): string;var  i: Integer;  s: string;begin  s := '';  for i := 1 to Pred(Length(AString)) do    if  ((Ord(AString[i]) >= 32) and (Ord(AString[i]) < 127)) then      s := s + AString[i];  Result := s;end; function DelDoubleSpace(const AString: string): string;var  s: string;  p: Integer;begin  Result := AString;  if (Length(AString) < 1) then    Exit;  s := AString;  repeat    p := Pos('  ', s);    if (p > 0) then      Delete(s, p, 1);  until p = 0;  Result := s;end; procedure TForm1.Button1Click(Sender: TObject);begin  Memo1.Text := DelDoubleSpace(FilterAscii('insert your text here'));end;Above would result in what you try to achieve.

Warning: Limited to ASCII

jamie:
I believe a function exists in the RTL to remove the tabs from a string and properly
replace them with spaces.

 I would need to look that up but I do remember seeing it somewhere.

EDIT
  Yes there is, Tab2Space but I noticed that it does not calculate the group segment of tabs verses the chars up to that point. It simple replaces the tab char with the number of spaces you indicate.
  Maybe a proper function should be added to the strutils ?

JLWest:
I'm Not sure there tabs. I run the string thru a CleanString function and then DelSpace1 function and then  DelDoubleSpace (written by KodeZwerg) and still having the problem of double spaces remaining in the string.

Will write a demo and post.

KodeZwerg:

--- Quote from: JLWest on November 18, 2022, 08:39:23 pm ---I'm Not sure there tabs. I run the string thru a CleanString function and then DelSpace1 function and then  DelDoubleSpace (written by KodeZwerg) and still having the problem of double spaces remaining in the string.

Will write a demo and post.

--- End quote ---
Try with my DelDoubleSpace(FilterAscii('text')) combo?

JLWest:
Line 1 is the string copied from hovering over the variable.

Line 2 is a copy and paste of the same string. (Notice double space between Integer and read)

Line 3 after FilterAscii function

Line 4 after DelDoubleSpace function

So I ran a DelSpace1 in lieu of DelDoubleSpace and it worked.

So it's the FilterAscii that is removing something in the string. I can live with that.

Still, wonder what it is in the string that stops DelSpace1 from working.

thanks


--- Code: Text  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---Line 1: *M1 #$0D#$0A#$0D#$0A  uses ... avglvltree; #$0D#$0A#$0D#$0A   public property TCustomStringMap.CompareItemsFunc: TListSortCompare   read GetCompareItemsFunc; #$0D#$0A #$0D#$0ALine 2: *M1 uses ... actnlist; public property TCustomActionList.ActionCount: Integer   read GetActionCount;Line 3: *M1 uses ... actnlist; public property TCustomActionList.ActionCount: Integer   read GetActionCountLine 4: *M1 uses ... actnlist; public property TCustomActionList.ActionCount: Integer read GetActionCount 

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version