Strings Functions

The Strings category contains the following functions:

Left

Function

Left

Location in PracticeScript

Functions->Strings

Purpose

Returns the specified number of leftmost characters from a character string.

Format

Left(Expression, Characters)

Expression specifies the character expression whose leftmost characters are returned.

Characters specifies the number of characters returned from the character expression. Left( ) returns the entire character expression if Characters is greater than the length of Expression. Left( ) returns an empty string if Characters is negative or 0.

Evaluates to

Characters are returned beginning with the first character on the left and continuing for a specified number of characters.

Example

Left("Melvin Jones", 5)
Evaluates to "Melvi".

Left(Person.LastName, 5)
Evaluates to "Stege" if the person's last name is Stegemiller. Evaluates to "Smith" if the person's last name is Smith. Evaluates to "Lee" if the person's last name is Lee.

Right

Function

Right

Location in PracticeScript

Functions->Strings

Purpose

Returns the specified number of rightmost characters from a character string.

Format

Right(Expression, Characters)

Expression specifies the character expression whose rightmost characters are returned.

Characters specifies the number of characters returned from the character expression. Right returns the entire character expression if Characters is greater than the length of Expression. Right returns an empty string if Characters is negative or 0.

Evaluates to

Characters are returned beginning with the last character on the right and continuing for a specified number of characters.

Example

Right("Melvin Jones", 5)
Evaluates to "Jones".

Right(Person.LastName, 5
Evaluates to "iller" if the person's last name is Stegemiller. Evaluates to "Smith" if the person's last name is Smith. Evaluates to "Lee" if the person's last name is Lee.

SubStr

Function

SubStr

Location in PracticeScript

Functions->Strings

Purpose

Returns a character string from the given character expression.

Format

SubStr(Expression, StartPosition, OptionalCharactersReturned)

Expression specifies the character expression from which the character string is returned.

StartPosition specifies the position in the character expression Expression from where the character string is returned. The first character of Expression is position 1.

OptionalCharactersReturned specifies the number of characters to return from Expression. If you omit OptionalCharactersReturned, characters are returned until the end of the character expression is reached.

Evaluates to

A character string from a character expression, starting at a specified position in the character expression and continuing for a specified number of characters.

Example

SubStr("Melvin", 1, 3)
Evaluates to "Mel".

SubStr("Melvin", 2, 2)
Evaluates to "el".

SubStr("Melvin", 4)
Evaluates to "vin".

Char

Function

Char

Location in PracticeScript

Functions->Strings

Purpose

Returns the character associated with the specified numeric ANSI code.

Format

Char(ANSICode).
ANSICode
specifies a number between 0 and 255 whose equivalent ANSI character Char returns. See the following table for popular ANSI codes.

Evaluates to

A single character corresponding to the numeric position of the character in the ANSI character table.

Example

Char(65) returns "A". Char(49) returns "1".

 

Character

ANSI

1

49

2

50

3

51

4

52

5

53

6

54

7

55

8

56

9

57

0

48

 

 

Character

ANSI lowercase

ANSI uppercase

a

97

65

b

98

66

c

99

67

d

100

68

e

101

69

f

102

70

g

103

71

h

104

72

i

105

73

j

106

74

k

107

75

l

108

76

m

109

77

n

110

78

o

111

79

p

112

80

q

113

81

r

114

82

s

115

83

t

116

84

u

117

85

v

118

86

w

119

87

x

120

88

y

121

89

z

122

90

Format

Function

Format

Location in PracticeScript

Functions->Strings

Purpose

Returns a character string from a numeric expression in a format determined by a format code.

Format

Format(Expression, FormatCode)
Expression specifies the numeric expression to be formatted. FormatCode specifies one or more format codes that determine how the expression is formatted. The following tables list the available format codes. All numbers are rounded to the last decimal position that appears in the formatting picture. If the number does not fit in the picture, asterisks are returned. If the picture is invalid, a series of '??' are returned.

Evaluates to

Formatted character string.

Example

Code

Function

9

A normal digit. Zeros are printed as-is (including leading 0s).

Z

If a leading 0 appears in the digit position, it is formatted as a space. Z is treated the same as a 9 after the decimal point.

,

The comma may be inserted in the number to divide digit positions. If a comma appears in a leading 0 position, it is formatted as a leading 0 would be (depending on the use of *, Z, or 9).

.

The decimal point (if present), aligns the formatted number. Decimal points are not valid for non-floating point numbers.

$

If only one-dollar sign appears in the picture, it is fixed in that position. Two or more dollar signs in the picture represent a floating sign. All but the last sign is formatted as spaces when leading 0s appear.

-

The minus sign may appear either at the front or end of the number only. If it appears at the front, two or more are required for a floating minus sign (i.e., it functions as the $).

*

 If a leading 0 appears in the digit position, it is formatted as a '*' character.

 

Integer numbers may also have the following characters in their output picture:

 

8   An octal digit.

H   A hexadecimal digit. The different number bases MAY NOT BE MIXED!

 

Expression

FormatCode

Resulting character string

1234.5678

9999999.99

0001234.57

1234.5678

ZZZ,ZZ9.99

1,234.57

1234.5678

$ZZ,ZZ9.99

$1,234.57

1234.5678

$$$,$$9.99

$1,234.57

1234.5678

$$Z,ZZ9.99

$1,234,57

4.5

***,$$9.99

*****$4.50

4.5

$**,**9.99

$*****4.50

-1234.5678

ZZZ,ZZ9.99

1,234.57

-1234.5678

-ZZ,ZZ9.99

-1,234.57

-1234.5678

--$,$Z9.99

-$1,234.57

-1234.5678

ZZZ,ZZ9.99 -

1,234.57 -

0.5

ZZZ,ZZZ.ZZ

.50

0.5

ZZZ,ZZ9.99

0.50

-0.5

$,$Z9.99

-$0.50

 

PadRight

Function

PadRight

Location in PracticeScript

Functions->Strings

Purpose

Returns a string of characters from an expression, padded with spaces or other characters on the right side to a specified length. If the expression has more characters than the specified length, PadRight() drops the excess characters off of the left end.

Format

PadRight(Expression, ResultSize, OptionalPadCharacter)
Expression
specifies the character expression to be padded.
ResultSize
specifies the total number of characters in the expression after it is padded.
OptionalPadCharacter
specifies the value to use for padding. This value is repeated as necessary to pad the expression to the specified number of characters. If you omit OptionalPadCharacter, spaces (ANSI character 32) are used for padding.

Evaluates to

A character string.

Example

PadRight("Hello", 10, "!")

Returns "Hello!!!!!"

PadRight("Test", 5)

Returns "Test " (note the trailing space)

PadRight(Person.LastName, 8, "X")

Evaluates to "SmithXXX" if the person's last name is Smith.; Evaluates to "Zebriski" if the person's last name is Zebriski. Evaluates to "gemiller" if the person's last name is Stegemiller.

PadLeft

Function

PadLeft

Location in PracticeScript

Functions->Strings

Purpose

Returns a string of characters from an expression, padded with spaces or other characters on the left side, to a specified length. If the expression has more characters than the specified length, PadLeft() drops the excess characters off of the right end.

Format

PadLeft(Expression, ResultSize, OptionalPadCharacter)Expression specifies the expression to be padded.

ResultSize specifies the total number of characters in the expression after it is padded.

OptionalPadCharacter specifies the value to use for padding. This value is repeated as necessary to pad the expression to the ResultSize. If you omit OptionalPadCharacter, spaces (ANSI character 32) are used for padding.

Evaluates to

A character string.

Example

PadLeft("Hello", 10, "!")
Returns "!!!!!Hello"

PadLeft("Test'", 5)
Returns " Test" (note the leading space)

PadLeft(Person.LastName, 8, "X")
Evaluates to "XXXSmith" if the person's last name is Smith. Evaluates to "Zebriski" if the person's last name is Zebriski. Evaluates to "Stegemil" if the person's last name is Stegemiller.

TrimRight

Function

TrimRight

Location in PracticeScript

Functions->Strings

Purpose

Returns a character string that results from removing the trailing blanks from a character expression.

Format

TrimRight(Expression)
Expression
specifies the character expression from which trailing blanks are trimmed.

Evaluates to

A character string.

Example

TrimRight("Hello ")
Returns "Hello".

TrimLeft

Function

TrimLeft

Location in PracticeScript

Functions->Strings

Purpose

Returns a character string that results from removing the leading blanks from a character expression.

Format

TrimLeft(Expression)
Expression
specifies the character expression from which leading blanks are trimmed.

Evaluates to

A character string.

Example

TrimLeft(" Hello")
Returns "Hello".

TrimAll

Function

TrimAll

Location in PracticeScript

Functions->Strings

Purpose

Returns a character string that results from removing the leading and trailing blanks from a character expression.

Format

TrimAll(Expression)
Expression
specifies the character expression from which leading and trailing blanks are trimmed.

Evaluates to

A character string.

Example

TrimAll(" Hello ")
Returns "Hello".

 

Related Topics

Using Functions

Function Definitions

Practice Answers

Date Functions

Special Functions

Time Functions

User Defined Functions

Prompt User for Info Functions