Add space after finding a character

Asked

Viewed 258 times

1

I have the following code that adds the contents of a button and a space after clicked

   procedure TForm3.Button1Click(Sender: TObject);
      begin
        if count = 0 then
          Edit1.Text := Edit1.Text + TLabel(Sender).caption+ ' ';

        if count = 1 then
          begin
            Edit2.Text := Edit2.Text + TLabel(Sender).caption+ ' ';
          end;
      end;

Saida: Dose = Max + Min

and another situation for number, which does not apply the spaces:

    procedure TForm3.Button29Click(Sender: TObject);
    begin
         if count = 0 then
          Edit1.Text := Edit1.Text + TLabel(Sender).caption;

        if count = 1 then
          begin
            Edit2.Text := Edit2.Text + TLabel(Sender).caption;
          end;

    end;
Saida: Dose = 10

But I was thinking that after the number I could find a text and the way I would make the character after the number would come out like this

Saida: Dose = 10AND 20

Where the right would be:

Saida: Dose = 10 AND 20

How to treat the function so that when the next character after the number is a letter, it adds a space?

  • you could always add space, and at the end of the operation use the Trim() ?

  • I could do that in a function, but if there’s an AND after the number, it wouldn’t do any good.

  • I mean, for both number and text, you add space, in your example, you just add to text, then at the end, you use Trim()

1 answer

2


You could create a function in the following templates, where Setofchar is a declared constant:

SetOfChar = set of 'A'..'z';

function Concatena(const TextoEdit, Caption: String): String;
begin
  if TextoEdit = '' then
    Result := Caption
  else if TextoEdit in SetOfChar then
    Result := TextoEdit + ' ' + Caption
  else
    Result := TextoEdit + Caption;
end;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.