You can use StringReplace:
var str:String; begin str:='The_aLiEn'+Chr(VK_TAB)+'Delphi'; ShowMessage(str); str:=StringReplace(str, chr(VK_Tab), '', [rfReplaceAll]); ShowMessage(str); end;
Disables all Tab characters from the given string. But you can improve it if you want to remove the leading and trailing tabs, you can also use the Pos function.
Edit: For a comment asking how to do this with Pos, here it is:
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;
This, of course, is the same approach of Maxey and a little more work than him. But if you do not have much time to complete the work, and if Pos is what you thought in the first place, then this can be done. You, the programmer, should and should think about optimization, not me. And if we talk about the limitations of optimization, with a little tweak to replace Pos with char, this will work faster than Maxeyโs code.
Edit to generalize Substr search:
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;