Delphi and Kylix

Moderators: pritaeas
Number of threads: 7264
Number of posts: 19073

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
TEdit Posted by Mozez on 12 Oct 2003 at 2:50 AM
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
Report
Re: TEdit Posted by Perran on 12 Oct 2003 at 4:27 AM
: 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.
Report
Re: TEdit Posted by jamesb800 on 12 Oct 2003 at 5:59 AM
: : 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;




Report
Re: TEdit Posted by zibadian on 12 Oct 2003 at 7:57 AM
: : : 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;


Report
Re: TEdit Posted by jamesb800 on 12 Oct 2003 at 11:31 AM
: : : : 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.




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.