Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use StringReplace:</p> <pre><code>var str:String; begin str:='The_aLiEn'+Chr(VK_TAB)+'Delphi'; ShowMessage(str); str:=StringReplace(str, chr(VK_Tab), '', [rfReplaceAll]); ShowMessage(str); end; </code></pre> <p>This omits all Tab characters from given string. But you can improve it, if you want leading and trailing tabs to be removed then you can use Pos function also.</p> <p><strong>Edit:</strong> For the comment asking how to do it with Pos, here it is:</p> <pre><code>var str:String; s, e: PChar; begin str:=Chr(VK_TAB)+Chr(VK_TAB)+'The_aLiEn'+Chr(VK_TAB)+'Delphi'+Chr(VK_TAB)+Chr(VK_TAB); s:=PChar(str); while Pos(Chr(VK_TAB), s)=1 do inc(s); e:=s; inc(e, length(s)-1); while Pos(Chr(VK_TAB), e)=1 do dec(e); str:=Copy(s, 1, length(s)-length(e)+1); ShowMessage(str); end; </code></pre> <p>It is of course <strong>the same</strong> approach by Maksee's and a bit more job to do as it is. But if there isn't much time to finish the work and if <strong>Pos</strong> is what you've thought first, then this is how it can be done. You, the programmer <strong>should</strong> and <strong>have to</strong> think about optimizations, not me. And if we're talking constraints of optimization, with a little tweak to replace Pos with char compare, this will run faster than Maksee's code.</p> <p><strong>Edit for Substr search generalization:</strong></p> <pre><code>function TrimStr(const Source, SubStr: String): String; var s, e: PChar; l: Integer; begin s:=PChar(Source); l:=Length(SubStr); while Pos(SubStr, s)=1 do inc(s, l); e:=s; inc(e, length(s)-l); while Pos(SubStr, e)=1 do dec(e, l); Result:=Copy(s, 1, length(s)-length(e)+l); end; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload