The string type is used for processing text.

It is simply a particular kind of array: an array of char.

Remember that char is the type used to store characters (any of the 256 character of the ASCII table).

You can use the following built-in functions to manipulate strings:

function inttostr(i: Longint): string; 
// converts an integer to a string 

function strtoint(s: string): Longint; 
// the opposite

function strtointdef(s: string; def: Longint): Longint; 
// Converts s to a number. If s doesn't represent a valid number, def is returned instead.

function copy (s: string; ifrom, icount: Longint): string;
// returns a part of the string s, ifrom is the position from where the copy starts, 
// icount is the number of char to be copied. 

function pos(substr, s: string): Longint; 
// returns the position of a substring into a string (kind of search function)

procedure delete(var s: string; ifrom, icount: Longint); 
// same as copy, but deletes a part of the string s

procedure insert(s: string; var s2: string; ipos: Longint): string;
// inserts the string s2 into the string s at position ipos

Function StrGet(var S : String; i : Integer) : Char; 
// returns the char of index i

procedure StrSet(c: Char; I : Integer; var s : String);
// sets in the string s the character of index i to the value c

Function Uppercase(s: string) : string; 
Function Lowercase(s: string) : string; 
// no comment

Function Trim (s: string) : string; 
//Removes leading and trailing spaces and control characters (ie ASCII 0-32) from s

Function Length(s: String) : Longint; 
// Returns the length of the string (equivalent of GetArrayLength for arrays)

procedure SetLength(var S: String; L: Longint);
// Sets the length of the string  (equivalent of SetArrayLength for arrays)

Function FloatToStr(e: Extended) : String; 
// Turns a extended number to a string

function StrToFloat(s: string): Extended; 
// Opposite

Function Padl (s: string;I : longInt) : string;
// Puts i spaces before s

Function Padr (s: string;I : longInt) : string; 
// Adds as many spaces needed to make a string of length i

Function Padz (s: string;I : longInt) : string; 
//  Is similar to Padl, but adds zeroes instead of spaces

Function Replicate(c: char;I : longInt) : string; 
// Builds a string containing i times the character c

Function StringOfChar(c: char;I : longInt) : string; 
// Creates a string where the character c is repeated i times

N.B: Always use single quotes when directly manipulating string or char types.

Var MyString1, MyString2, MyString3 : string;
Var char1 : char;
MyString1 := 'Hello';
MyString2 :='how are';
MyString3 := MyString1 + ' ' + MyString2 + ' ' + 'you?';
// MyString3 now equals 'Hello how are you?'
Char1 := 'h';
StrSet(Char1, 0, MyString1);
// MyString1 now equals 'hello' (lowercase h)
StrSet('H', 0, Mystring1);
// MyString1 is again 'Hello' (uppercase H)

See also

version 4.0.200329

Edit All Pages