Attaches Source to Dest and returns Dest.
Program Example11; Uses strings; { Program to demonstrate the StrCat function. } Const P1 : PChar = 'This is a PChar String.'; Var P2 : PChar; begin P2:=StrAlloc (StrLen(P1)*2+1); StrMove (P2,P1,StrLen(P1)+1); { P2=P1 } StrCat (P2,P1); { Append P2 once more } Writeln ('P2 : ',P2); end.
Compares the null-terminated strings S1 and S2. The result is
Copy the null terminated string in Source to Dest, and returns a pointer to Dest. Dest needs enough room to contain Source, i.e. StrLen(Source)+1 bytes.
Program Example4; Uses strings; { Program to demonstrate the StrCopy function. } Const P : PCHar = 'This is a PCHAR string.'; var PP : PChar; begin PP:=StrAlloc(Strlen(P)+1); STrCopy (PP,P); If StrComp (PP,P)<>0 then Writeln ('Oh-oh problems...') else Writeln ('All is well : PP=',PP); end.
Removes the string in P from the heap and releases the memory.
Program Example17; Uses strings; { Program to demonstrate the StrDispose function. } Const P1 : PChar = 'This is a PChar string'; var P2 : PChar; begin Writeln ('Before StnNew : Memory available : ',MemAvail); P2:=StrNew (P1); Writeln ('After StrNew : Memory available : ',MemAvail); Writeln ('P2 : ',P2); StrDispose(P2); Writeln ('After StrDispose : Memory available : ',MemAvail); end.
Copies the Null-terminated string in Source to Dest, and returns a pointer to the end (i.e. the terminating Null-character) of the copied string.
Program Example6; Uses strings; { Program to demonstrate the StrECopy function. } Const P : PChar = 'This is a PCHAR string.'; Var PP : PChar; begin PP:=StrAlloc (StrLen(P)+1); If Longint(StrECopy(PP,P))-Longint(PP)<>StrLen(P) then Writeln('Something is wrong here !') else Writeln ('PP= ',PP); end.
Returns a pointer to the end of P. (i.e. to the terminating null-character.
Program Example6; Uses strings; { Program to demonstrate the StrEnd function. } Const P : PChar = 'This is a PCHAR string.'; begin If Longint(StrEnd(P))-Longint(P)<>StrLen(P) then Writeln('Something is wrong here !') else Writeln ('All is well..'); end.
Compares the null-terminated strings S1 and S2, ignoring case. The result is
Program Example8; Uses strings; { Program to demonstrate the StrLComp function. } Const P1 : PChar = 'This is the first string.'; P2 : PCHar = 'This is the second string.'; Var L : Longint; begin Write ('P1 and P2 are '); If StrComp (P1,P2)<>0 then write ('NOT '); write ('equal. The first '); L:=1; While StrLComp(P1,P2,L)=0 do inc (L); dec(l); Writeln (l,' characters are the same.'); end.
Adds MaxLen characters from Source to Dest, and adds a terminating null-character. Returns Dest.
Program Example12; Uses strings; { Program to demonstrate the StrLCat function. } Const P1 : PChar = '1234567890'; Var P2 : PChar; begin P2:=StrAlloc (StrLen(P1)*2+1); P2^:=#0; { Zero length } StrCat (P2,P1); StrLCat (P2,P1,5); Writeln ('P2 = ',P2); end.
Compares maximum L characters of the null-terminated strings S1 and S2. The result is
Program Example8; Uses strings; { Program to demonstrate the StrLComp function. } Const P1 : PChar = 'This is the first string.'; P2 : PCHar = 'This is the second string.'; Var L : Longint; begin Write ('P1 and P2 are '); If StrComp (P1,P2)<>0 then write ('NOT '); write ('equal. The first '); L:=1; While StrLComp(P1,P2,L)=0 do inc (L); dec(l); Writeln (l,' characters are the same.'); end.
Copies MaxLen characters from Source to Dest, and makes Dest a null terminated string.
Program Example5; Uses strings; { Program to demonstrate the StrLCopy function. } Const P : PCHar = '123456789ABCDEF'; var PP : PCHar; begin PP:=StrAlloc(11); Writeln ('First 10 characters of P : ',StrLCopy (PP,P,10)); end.
Returns the length of the null-terminated string P.
Program Example1; Uses strings; { Program to demonstrate the StrLen function. } Const P : PChar = 'This is a constant pchar string'; begin Writeln ('P : ',p); Writeln ('length(P) : ',StrLen(P)); end.
Compares maximum L characters of the null-terminated strings S1 and S2, ignoring case. The result is
Converts P to an all-lowercase string. Returns P.
Program Example14; Uses strings; { Program to demonstrate the StrLower and StrUpper functions. } Const P1 : PChar = 'THIS IS AN UPPERCASE PCHAR STRING'; P2 : PChar = 'this is a lowercase string'; begin Writeln ('Uppercase : ',StrUpper(P2)); StrLower (P1); Writeln ('Lowercase : ',P1); end.
Copies MaxLen characters from Source to Dest. No terminating null-character is copied. Returns Dest.
Program Example10; Uses strings; { Program to demonstrate the StrMove function. } Const P1 : PCHAR = 'This is a pchar string.'; Var P2 : Pchar; begin P2:=StrAlloc(StrLen(P1)+1); StrMove (P2,P1,StrLen(P1)+1); { P2:=P1 } Writeln ('P2 = ',P2); end.
Copies P to the Heap, and returns a pointer to the copy.
Program Example16; Uses strings; { Program to demonstrate the StrNew function. } Const P1 : PChar = 'This is a PChar string'; var P2 : PChar; begin P2:=StrNew (P1); If P1=P2 then writeln ('This can''t be happening...') else writeln ('P2 : ',P2); end.
Converts a null terminated string in P to a Pascal string, and returns this string. The string is truncated at 255 characters.
Program Example3; Uses strings; { Program to demonstrate the StrPas function. } Const P : PChar = 'This is a PCHAR string'; var S : string; begin S:=StrPas (P); Writeln ('S : ',S); end.
Converts the Pascal string in Source to a Null-terminated string, and copies it to Dest. Dest needs enough room to contain the string Source, i.e. Length(Source)+1 bytes.
Program Example2; Uses strings; { Program to demonstrate the StrPCopy function. } Const S = 'This is a normal string.'; Var P : Pchar; begin p:=StrAlloc (length(S)+1); if StrPCopy (P,S)<>P then Writeln ('This is impossible !!') else writeln (P); end.
Returns a pointer to the first occurrence of S2 in S1. If S2 does not occur in S1, returns Nil.
Program Example15; Uses strings; { Program to demonstrate the StrPos function. } Const P : PChar = 'This is a PChar string.'; S : Pchar = 'is'; begin Writeln ('Position of ''is'' in P : ',longint(StrPos(P,S))-Longint(P)); end.
Returns a pointer to the last occurrence of the character C in the null-terminated string P. If C does not occur, returns Nil.
Returns a pointer to the first occurrence of the character C in the null-terminated string P. If C does not occur, returns Nil.
Program Example13; Uses strings; { Program to demonstrate the StrScan and StrRScan functions. } Const P : PChar = 'This is a PCHAR string.'; S : Char = 's' ; begin Writeln ('P, starting from first ''s'' : ',StrScan(P,s)); Writeln ('P, starting from last ''s'' : ',StrRScan(P,s)); end.
Converts P to an all-uppercase string. Returns P.