Copies a substring of any length from a specific position in a
string (text or code) to a new string.
|
NewString := COPYSTR(String, Position[, Length])
|
Parameters
- String
-
Type: Text constant or code
The string that you want to copy from.
- Position
-
Type: Integer
The position of the first character to copy. The value of
Position must be greater than zero
(0). If Position is greater than the
length of the string, the system returns an empty string.
- Length
-
Type: Integer
The number of characters to copy. Length must be greater than zero (0). If the
value of Length results in
Position + Length > (total length of the string), then
the result includes all the characters from Position to the end of
the string.
Property Value/Return Value
Type: Text constant or code
The resulting string or substring
Remarks
Example
This example requires that you create the following
variables and text constants in the C/AL Globals window.
Variable name |
DataType |
Length |
Str
|
Text
|
30
|
Position
|
Integer
|
|
Length
|
Integer
|
|
NewStr
|
Text
|
30
|
Text constant |
ENU value |
Text000
|
Using the COPYSTR function
|
Text001
|
The original string is:\>%1<
|
Text002
|
The copied string is:\>%1<
|
|
Copy Code |
Str := Text000;
Position := 7;
Length := 8;
MESSAGE(Text001, Str);
NewStr := COPYSTR(Str, Position, Length);
MESSAGE(Text002, NewStr);
|
The first message window shows the original string:
The original string is:
>Using the COPYSTR function<
The second message window shows the copied string:
The copied string is:
>the COPY<
See Also