Get whitespace from a string

1

I'm looking for something like this:

I have a string like this:

      texto
           texto
  texto
                 texto

Type, with spaces before the text, and I need to get this space, and save in a variable, this using Delphi 7. Only the text is not always text, it can be 123 , it can be another word, but I need to save the size of the space, because I'll need it later.

Any suggestions? I tried pos/copy , but to no avail.

    
asked by anonymous 26.05.2015 / 22:14

1 answer

2

My Pascal is already very forgetful but I think you can do anything like this:

Var S : String;

S:=StringOfChar(' ',Length(ASuaVariavel) - Length(TrimLeft(AsuaVariavel));  

Edit after your comment

In the question, you say that the strings have spaces at the beginning, in the comment they refer to as Tabs , in which case the code needs to be changed.

var
  suaString : string;
  TAB : char;
  tabCount : Integer;
  stringOfTabs : string;
begin

  TAB := #9;
  suaString:= TAB + TAB + TAB + 'Texto';
  tabCount := Length(suaString) - Length(TrimLeft(suaString));
  stringOfTabs := StringOfChar(TAB,tabCount);

  writeln('A sua string: ', suaString);
  writeln('Numero de Tabs: ', tabCount);
  writeln(stringOfTabs + 'Tabs aplicados a outra string');

end.

See the Ideone

    
26.05.2015 / 22:30