Like many other languages, Delphi allows you to store letters, words, and sentences in single variables. These can be used to store and display such things as user details, screen titles and so on. A letter is stored in a single character variable type, such as Char, and words and sentences stored in string types, such as String. Here are the different text types in Delphi:

We'll cover the character and string types in turn, and then look at some of the large range of string processing routines provided by the Delphi run time library.

Characters

Single character variables hold a single character of text. Normally, this can be held in one byte. AnsiChar types are exactly one byte in size, and can hold any of the characters in the Ansi character set.

The ansi character set derived from the earlier ascii character set. Both were designed around European characters, which comfortably fitted into 256 values, the capacity of a single byte. For a long time, this was the easy way to handle text. But this left many countries, especially in Asia, out of the picture.

The WideChar type can support double-byte characters, which can hold numeric representations of the vast alphabets of China, Japan and so on. These are called International characters. International applications must use WideChar and WideString types.

Strings

A single character is useful when parsing text, one character at a time. However, to handle words and sentences and screen labels and so on, strings are used. A string is literally a string of characters. It can be a string of Char, AnsiChar or WideChar characters.

Assigning to and from a string

A ShortString is a fixed 255 characters long. A String (by default) is the same as an AnsiString, and is of any length you want. WideStrings can also be of any length. Their storage is dynamically handled. In fact, if you copy one string to another, the second will just point to the contents of the first.

source is now set to : Hello World target is now set to : Hello World last is now set to : Don't do that

String operators

There are a number of primitive string operators that are commonly used:

+ Concatenates two strings together= Compares for string equality< Is one string lower in sequence than another<= Is one string lower or equal in sequence with another> Is one string greater in sequence than another>= Is one string greater or equal in sequence with another<> Compares for string inequality

CurrToStrF Convert a currency value to a string with formatting DateTimeToStr Converts TDateTime date and time values to a string DateTimeToString Rich formatting of a TDateTime variable into a string DateToStr Converts a TDateTime date value to a string FloatToStr Convert a floating point value to a string FloatToStrF Convert a floating point value to a string with formatting Format Rich formatting of numbers and text into a string FormatCurr Rich formatting of a currency value into a string FormatDateTime Rich formatting of a TDateTime variable into a string FormatFloat Rich formatting of a floating point number into a string IntToHex Convert an Integer into a hexadecimal string IntToStr Convert an integer into a string Str Converts an integer or floating point number to a string

Converting from strings to numbers

StringToWideChar Converts a string into a WideChar 0 terminated buffer StrToCurr Convert a number string into a currency value StrToDate Converts a date string into a TDateTime value StrToDateTime Converts a date+time string into a TDateTime value StrToFloat Convert a number string into a floating point value StrToInt Convert an integer string into an Integer value StrToInt64 Convert an integer string into an Int64 value StrToInt64Def Convert a string into an Int64 value with default StrToIntDef Convert a string into an Integer value with default StrToTime Converts a time string into a TDateTime value Val Converts number strings to integer and floating point values