: : : : I have a TEdit with a Text in which I want to place a space beetween digit 4 and 5, 8 and so one and so one.
: : : :
: : : : Example:
: : : : Edit1.Text := '298592845792845928';
: : : :
: : : : The new text will be:
: : : : 2985 9284 5792 8459 28
: : : :
: : : : How can I do that?
: : : :
: : : : I also want to assign every of these blocks of 4 digits to a variable that I can use later.
: : : :
: : : : Mozez
: : : :
: : : Assign each of the blocks of four to individual variables first:
: : :
: : : StrVar1 := copy(Edit1.Text,1,4);
: : : StrVar2 := copy(Edit1.Text,5,8); //etc.
: : :
: : : Then concatenate the strings with spaces in between the variables.
: : :
: :
: : Here is what I came up with
: :
: :
: : procedure TForm1.Button1Click(Sender: TObject);
: : var
: : s,s1,s2,s3,s4:string;
: : begin
: : Edit1.Text := '298592845792845928';
: : s:=copy(Edit1.Text,1,4); //1st position 4chars
: : s1:=copy(Edit1.Text,5,4); //5th position 4 chars..and so on
: : s2:=copy(Edit1.Text,9,4);
: : s3:=copy(Edit1.Text,13,4);
: : s4:=copy(Edit1.Text,17,2);
: : Edit2.Text:=(s+' '+s1+' '+s2+' '+s3+' '+s4);
: : end;
: :
: :
: The code itself is correct, but you could streamline it by removing all the temporary string variables. Here's what the code then will look like:
:
: procedure TForm1.Button1Click(Sender: TObject);
: begin
: Edit1.Text := '298592845792845928';
: Edit2.Text := copy(Edit1.Text,1,4) + ' ' +
: copy(Edit1.Text,5,4) + ' ' +
: copy(Edit1.Text,9,4) + ' ' +
: copy(Edit1.Text,13,4) + ' ' +
: copy(Edit1.Text,17,2;
: end;
:
:
:
I get it....but, he wanted to be able to use the variables later.