# Text Routins

Tags:

### Comparison of text strings

#### function AnsiCompareStr(S1, S2: string): Integer;

Compares S1 to S2, with case sensitivity. The return value is less than 0 if S1 < S2, 0 if S1 = S2, or greater than 0 if S1 > S2.

#### function AnsiCompareText(S1, S2: string): Integer;

Compares S1 to S2, without case sensitivity. The return value is less than 0 if S1 < S2, 0 if S1 = S2, or greater than 0 if S1 > S2.

#### function CompareStr(S1, S2: string): Integer;

Compare two strings S1 to S2 with case-sensitivity. The return value is less than 0 if S1 < S2, 0 if S1 = S2, or greater than 0 if S1 > S2. Use CompareText to compare strings without case-sensitivity.

#### function CompareText(S1, S2: string): Integer;

Compare two strings S1 to S2 for equality without case-sensitivity. The return value is less than 0 if S1 < S2, 0 if S1 = S2, or greater than 0 if S1 > S2. Use CompareStr to compare strings with case-sensitivity.

### Converting text strings to other formats and vice versa

#### function FloatToStr(X: Double): string;

Converts a floating-point value to a string. If the given value is a NAN (not-a-number), the resulting string is 'NAN'. If the given value is positive infinity, the resulting string is 'INF'. If the given value is negative infinity, the resulting string is '-INF'.

Приклад на TechEditor Pascal Script (.PSC):

var  A: Double;  S: string;begin  A := Sin(Math.Pi / 4);  S := FloatToStr(A); // S='0.707..';end;

#### function Format(Fmt: string; Args: array of const): string;

Returns a formatted string assembled from a format string Fmt and an array of arguments Args. Format returns the results of applying the arguments in Args to the format string Fmt.

Fmt string passed to the string formatting routines contain two types of objects — literal characters and format specifiers. Literal characters are copied word for word to the resulting string. Format specifiers fetch arguments from the argument list and apply the formatting to them.

A format specifier begins with a % character:

"%" [index ":"] ["-"] [width] ["." prec] type

After the percent sign come the following elements, in this order:

1. An optional argument zero-offset index specifier (that is, the first item has index 0), [index ":"].
2. An optional left justification indicator, ["-"].
3. An optional width specifier, [width].
4. An optional precision specifier, ["." prec].
5. The conversion type character, type.

The following table summarizes the possible values for type:

• d — Decimal. The argument must be an integer value. The value is converted to a string of decimal digits. If the format string contains a precision specifier, it indicates that the resulting string must contain at least the specified number of digits; if the value has less digits, the resulting string is left-padded with zeros.
• u — Unsigned decimal. Similar to d, but no sign is output.
• e — Scientific. The argument must be a floating-point value. The value is converted to a string of the form "-d.ddd...E+ddd". The resulting string starts with a minus sign if the number is negative. One digit always precedes the decimal point. The total number of digits in the resulting string (including the one before the decimal point) is given by the precision specifier in the format string; a default precision of 15 is assumed if no precision specifier is present. The "E" exponent character in the resulting string is always followed by a plus or minus sign and at least three digits.
• f — Fixed. The argument must be a floating-point value. The value is converted to a string of the form "-ddd.ddd...". The resulting string starts with a minus sign if the number is negative. The number of digits after the decimal point is given by the precision specifier in the format string—a default of 2 decimal digits is assumed if no precision specifier is present.
• g — General. The argument must be a floating-point value. The value is converted to the shortest possible decimal string using fixed or scientific format. The number of significant digits in the resulting string is given by the precision specifier in the format string; a default precision of 15 is assumed if no precision specifier is present. Trailing zeros are removed from the resulting string, and a decimal point appears only if necessary. The resulting string uses the fixed-point format if the number of digits to the left of the decimal point in the value is less than or equal to the specified precision, and if the value is greater than or equal to 0.00001. Otherwise the resulting string uses scientific format.
• n — Number. The argument must be a floating-point value. The value is converted to a string of the form "-d,ddd,ddd.ddd...". The n format corresponds to the f format, except that the resulting string contains thousand separators.
• s — String. The argument must be a character, a string, or a PChar value. The string or character is inserted in place of the format specifier. The precision specifier, if present in the format string, specifies the maximum length of the resulting string. If the argument is a string that is longer than this maximum, the string is truncated.

Приклад на TechEditor Pascal Script (.PSC):

#### function IntToStr(X: Integer): string;

Converts an integer X to a string. Returns the result of conversation.

Приклад на TechEditor Pascal Script (.PSC):

var  A: Integer;  S: string;begin  A := 2 + 5;  S := IntToStr(A); // S='7';end;

#### function StrToFloat(S: string): Double;

Converts a given string S to a floating-point value.

Приклад на TechEditor Pascal Script (.PSC):

var  S: string;  X: Double;begin  S := '1.456';  X := StrToFloat(S); // X=1.456  end;

#### function StrToInt(S: string): Integer;

Converts a given string S to integer value.

Приклад на TechEditor Pascal Script (.PSC):

var  S: string;  X: Integer;begin  S := '-15';  X := StrToInt(S); // X=-15  end;

#### function StrToIntDef(S: string; DefValue: Integer): Integer;

Function converts the string S, which represents an integer-type number, into a number. If S does not represent a valid number, StrToIntDef returns DefValue.

Приклад на TechEditor Pascal Script (.PSC):

var  S: string;  X: Integer;begin  S := '25 cm';  X := StrToIntDef(S, 0); // X=0 because '25 cm' is invalid integer value!  end;

#### function Math.StrToFloatDef(S: string; DefValue: Double): Double;

Function converts the string S into a floating-point value. If S does not represent a valid floating-point value, function returns DefValue.

Приклад на TechEditor Pascal Script (.PSC):

var  S: string;  X: Double;begin  S := '25.5 cm';  X := Math.StrToFloatDef(S, 1.0); // X=1 because '25.5 cm' is incorrect value!  end;

### Case conversions

#### function AnsiLowerCase(S: string): string;

Returns a string S, but with all letters converted to lowercase.

#### function AnsiUpperCase(S: string): string;

Returns a string S, but with all letters converted to uppercase.

#### function LowerCase(S: string): string;

Returns a string S, but with all letters converted to lowercase.

Приклад на TechEditor Pascal Script (.PSC):

var  S: string;begin  S := LowerCase('SUCCESS'); // S='success';end;

#### function UpperCase(S: string): string;

Returns a string S, but with all letters converted to uppercase.

Приклад на TechEditor Pascal Script (.PSC):

var  S: string;begin  S := UpperCase('success'); // S='SUCCESS';end;

### Other routins

#### procedure Delete(var S: string; Index, Count: Integer);

Procedure removes a substring of Count characters from string S, starting with S[Index] character. If Index is larger than the length of the string (or less than 1), no characters are deleted. If Count specifies more characters than remain starting at Index, Delete removes the rest of the string. If Count is less than or equal to 0, no characters are deleted.

Приклад на TechEditor Pascal Script (.PSC):

var  S: string;begin  S := 'TechEditor';  Delete(S, 1, 4); // S='Editor'end;

#### function Chr(X: Byte): Char;

Chr returns the character with the ordinal value X (ASCII value).

Приклад на TechEditor Pascal Script (.PSC):

var  C: Char; begin
C := Chr(82); // C='R' end;

#### function Copy(S: string; Index, Count: Integer): string;

Copy returns a substring of a string S containing Count characters starting at S[Index]. If Index is larger than the length of S, Copy returns an empty string. If Count specifies more characters than are available, only the characters or elements from S[Index] to the end of S are returned.

Приклад на TechEditor Pascal Script (.PSC):

var  S: string;begin  S := 'TechEditor';
S := Copy(S, 1, 4); // S='Tech' end; 

#### function Length(S: string): Integer;

Returns the number of characters in a string.

Приклад на TechEditor Pascal Script (.PSC):

var  X: Integer; begin  X := Length('hello'); // x=5end;

#### function Ord(C: Char): Byte;

Returns the ordinal value of a character C in accordance to ASCII table.

Приклад на TechEditor Pascal Script (.PSC):

var  i: Integer;   begin
i := Ord('R'); // i=82   end;

#### function Pos(SearchStr, S: string): Integer;

Function returns the index of the first occurrence of SearchStr in string S.

Приклад на TechEditor Pascal Script (.PSC):

var  i: Integer;   begin
i := Pos('Edit', 'TechEditor'); // i=5end;

#### function Trim(S: string): string;

Function removes leading and trailing spaces and control characters from the given string S.

Приклад на TechEditor Pascal Script (.PSC):

var  S: string;begin  S := Trim('  Dystlab TechEditor '); // S='Dystlab TechEditor'end;

#### function TrimLeft(S: string): string;

Function removes blank and control characters from the left side of a string.

Приклад на TechEditor Pascal Script (.PSC):

var  S: string;begin  S := Trim('  Dystlab TechEditor '); // S='Dystlab TechEditor 'end;

#### function TrimRight(S: string): string;

Function removes blank and control characters from the right side of a string.

Приклад на TechEditor Pascal Script (.PSC):

var  S: string;begin  S := Trim('  Dystlab TechEditor '); // S='  Dystlab TechEditor'end;

### Users Online

No members to show currently