Delphi character and string [4]-string, character pointer and character array

Source: Internet
Author: User
// String character array var arr: array [0 .. 5] of char; STR: string; begin {The String constant can be directly assigned to the character array, but not to the character array.} arr: = 'delphi '; showmessage (ARR ); {Delphi} {the character array can be directly assigned to the string variable} STR: = arr; showmessage (STR); {Delphi} {in fact, the string also contains an array of characters, therefore, the index can be accessed, but its index starts from 1} showmessage (STR [1]); {d} showmessage (ARR [0]); {d} {, but a string variable cannot be assigned to the character array} // arr: = STR; {error; this must be implemented by other means, such as copying or moving the memory} end;

 

// Character array> character pointer var arr: array [0 .. 6] of char; P: pchar; begin arr: = 'delphi '; {if the character array is directly given to the character pointer, the result is not safe, because the character pointer needs to find a null character (#0) to end} {give #0 the last element of the array.} arr [length (ARR)-1]: = #0; p: = arr; showmessage (p); {Delphi} {What If I gave #0 to the center ?} Arr [3]: = #0; P: = arr; showmessage (p); {del; truncated} end;

 

// String constant> character array constant

Const arr1: array [0 .. 5] of char = 'delphi '; arr2: array [0 .. 5] of ansichar = ansistring ('delphi '); begin showmessage (arr1 [0]); {d} showmessage (arr2 [0]); {d} 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.