Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Closed Thread
 
Thread Tools Display Modes
  #1  
Old 07-10-2012, 08:35 AM
bitzn bitzn is offline
Member
 
Join Date: Jun 2009
Posts: 34
Default Every four?

You have a string 64 chars long. You need to insert a character every 4 characters -- therefore, you need to add a total of 16 new characters.

What is the best way to do this? The only way I can think of is to use a case statement for position 4, 8, 12, and so on... Is there a better way?
  #2  
Old 07-10-2012, 09:23 AM
Jasser Jasser is offline
Moderator
 
Join Date: Jan 2005
Location: Saudi Arabia
Posts: 4,764
Default

Try:


Code:
var
          i, c    : Integer;
          sBuffer : String;
begin
          sBuffer := '0123456789012345678901234567890123456789012345678901234567890123';

          c := 0;

          for i:=Length(sBuffer) downto 2 do begin
              Inc(c);

              if c = 4 then begin
                 c := 0;

                 Insert('*',sBuffer,i);
              end;
          end;

          Showmessage( sBuffer );
__________________
Regards,
Abdulaziz Jasser
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 12:38 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.