Difference between dupestring and stringofchar-Reply to "e @ Changkong"

Source: Internet
Author: User
Problem Source: http://www.cnblogs.com/del/archive/2008/06/04/1101970.html#1217512
Stringofchar is a function that repeats "character" into "string;

Dupestring is a function that repeats "string" into "New String;

Stringofchar comes from the system unit and can be used directly;

Dupestring comes from the strutils unit, which requires uses strutils;

If it is only repeated "characters", of course, stringofchar should be used, which is an assemblyCodeThe implementation speed will be slightly better.

The following is the test code:

Unit unit1; interfaceuses windows, messages, extensions, variants, classes, graphics, controls, forms, dialogs, stdctrls; Type tform1 = Class (tform) button1: tbutton; Procedure formcreate (Sender: tobject); Procedure button1click (Sender: tobject); end; var form1: tform1; implementation {$ R *. DFM} uses strutils; {dupestring from this unit} procedure tform1.formcreate (Sender: tobject); var STR: string; begin STR: = system. stringofchar ('A', 5); showmessage (STR); {AAAAA} STR: = strutils. dupestring ('A', 5); showmessage (STR); {AAAAA} STR: = strutils. dupestring ('abc', 5); showmessage (STR); {abcabcabcabcabc} end; {stringofchar is certainly faster if it is only repeated characters; speed test:} procedure tform1.button1click (Sender: tobject); var T1, T2: Cardinal; I: integer; begin T1: = gettickcount; for I: = 0 to 1000000 do dupestring ('A', 5); T1: = gettickcount-T1; t2: = gettickcount; for I: = 0 to 1000000 do stringofchar ('A', 5); t2: = gettickcount-t2; showmessagefmt ('dupestring: % d; stringofchar: % d', [T1, T2]); end.
 
  
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.