Mid – PB Docs 126

Mid PowerScript function

Description

Obtains a specified number of characters from a specified
position in a string.

Syntax

Argument

Description

string

The string from which you want characters
returned.

start

A long specifying the position of the
first character you want returned. (The position of the first character
of the string is 1).

length (optional)

A long whose value is the number of characters
you want returned. If you do not enter length or
if length is greater than the number of characters
to the right of start, Mid returns
the remaining characters in the string.

Return Values

String. Returns characters specified
in length of string starting
at character start. If start is
greater than the number of characters in string,
the Mid function returns the empty string (“”).
If length is greater than the number of characters remaining
after the start character, Mid returns
the remaining characters. The return string is not filled with spaces
to make it the specified length. If any argument’s value
is null, Mid returns null.

Usage

To search a string for the position of the substring that
you want to extract, use the Pos function. Use
the return value for the start argument of Mid.
To extract a specified number of characters from the beginning or
end of a string, use the Left or the Right function.

Examples

This statement returns RUTH:

This statement returns “”:

This statement returns BE RUTH:

These statements store the characters in the SingleLineEdit sle_address from the
40th character to the end in ls_address_extra:

The following user-defined function, called str_to_int_array,
converts a string into an array of integers. Each integer in the
array will contain two characters (one characters as the high byte
(ASCII value * 256) and the second character as the low
byte). The function arguments are str, a string
passed by value, and iarr, an integer array
passed by reference. The length of the array is initialized before
the function is called. If the integer array is longer than the
string, the script stores spaces. If the string is longer, the script
ignores the extra characters.

To call the function, use code like the following:

The str_to_int_array function
is:

For sample code that converts the integer array back to a
string, see Asc.

See Also


Document get from Powerbuilder help
Thank you for watching.
Was this article helpful?
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x