fbpx

User's Guide

Text routines

Star InactiveStar InactiveStar InactiveStar InactiveStar Inactive
 

Text routines that you can use in your TechEditor applications.

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'.

 Example as 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.

 Example as TechEditor Pascal Script (.PSC):

Example 1

var
X: Double;
S: string;

begin
X := 15.62;
S := Format('%1.2f', [X]);
ShowMessage(S);
end;

To display the character % (a part of text), use the sequence %%.

Example 2

Format('%d%%', [100])); // displays '100%'

Example 3

Index, width, and precision specifiers can be specified directly, using a decimal digit string (for example "%10d"), or indirectly, using an asterisk character (for example "%*.*f"). When using an asterisk, the next argument in the argument list becomes the value that is actually used. Note that width is an integer value, while precision is an unsigned integer value. For example,

Format ('%*.*f', [8, 2, 123.456]);

is equivalent to:

Format ('%8.2f', [123.456]);

A width specifier sets the minimum field width for a conversion. If the resulting string is shorter than the minimum field width, it is padded with blanks to increase the field width. The default is to right-justify the result by adding blanks in front of the value, but if the format specifier contains a left-justification indicator (an "-" en dash character preceding the width specifier), the result is left-justified by adding blanks after the value.

An index specifier sets the current argument list index to the specified value. The index of the first argument in the argument list is 0. Using index specifiers, it is possible to format the same argument multiple times. For example, "Format('%d %d %0:d %1:d', [10, 20])" produces the string '10 20 10 20'.

Example 'How to create math equation using Format function':

format example

function IntToStr(X: Integer): string;

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

 Example as 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.

 Example as 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.

 Example as 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.

 Example as 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.

 Example as 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.

 Example as 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.

 Example as 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.

 Example as 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).

 Example as 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.

 Example as 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.

 Example as TechEditor Pascal Script (.PSC):

var
X: Integer;

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

function Ord(C: Char): Byte;

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

 Example as 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.

 Example as TechEditor Pascal Script (.PSC):

var
i: Integer;

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

function Trim(S: string): string;

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

 Example as 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.

 Example as 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.

 Example as TechEditor Pascal Script (.PSC):

var
S: string;

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

 

Events

Sorry, we currently have no events.
View All Events

English forum

Simple calculator in TechEditor in 10 minutes!

Ontario Building Code 2012 | Load combination (Free Application & Report Template)

Videoreview version 1.0

New articles

Dystlab™ — Project for Engineers

Dystlab™. All rights reserved.

Address in Canada: 223-2275 Lake Shore Boulevard West, Toronto, ON, M8V 3Y3

Address in Ukraine: 76006, Ivano-Frankivsk, st. Ivana Mykolaichuka 17/97

E-mail:
technot needed texteditoranother not needed text@dystlabdummy text.store

Telegram:
https://t.me/techeditor

Legal information

Dystlab™ is a trademark registered in the State Register of Certificates of Ukraine for Goods and Services Marks 26.02.2018, certificate No. 238304. Owner: entepreneur Artomov V.E., EGRPOU/ITN: 3003314690.

All the most interesting about TechEditor — in Twitter. Join us now!

TechEditor Twitter