In Corel SCRIPT, a string is the only data type that is not numeric; that is, a string is a series of characters that is treated as a unit of information. Strings are explicitly declared using the $ suffix or the data type name STRING. Strings must be enclosed in double quotation marks, and can hold up to 32,765 characters including lower and uppercase letters, numbers, and punctuation marks. Strings can use any of the 256 ANSI characters for Windows applications (code 0 to 255).
Punctuation and certain character codes for items such as tabs and hard returns cannot be directly entered within a string's double quotation marks. The CHR function is often used to add these special characters. For example, to add double quotation marks to a string variable, use character code 34:
MESSAGE "Example"

MESSAGE CHR(34)+"Example"+CHR(34)

You can also use this function to add a return and a line feed within a string, with character 13 and 10, respectively:
MESSAGE "String 1"+CHR(13)+"String 2"

The result will be the two strings on separate lines, as displayed in the message box.
Corel SCRIPT has a number of string-oriented functions that allow the user to manipulate strings. Some of them were discussed on the previous page (CHR, VAL, STR, ASC, CSTR, HEX). Below the rest of most useful string functions are explained.
INSTR(String1$,String2$,Pos)
Returns the position of the character of the first occurrence of a string within another string. If the specified string is not found, the function returns 0. String1$ is the string within which the search is made. String2$ is the search string, i.e. the string being serached. The third parameter Pos is optional. It specifies the first character position in string String1$ to start searching from. If it is omitted, 1 (the beginning) is assumed.
Examples:
a%=INSTR("Hello, World!","World")
a is assigned 8 because the first string ("Hello, World!") contains the second ("World") that starts from the position 8:
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| H | e | l | l | o | , | W | o | r | l | d | ! |
v%=INSTR("Hello, World!","o")
After the assignment, v becomes 5:
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| H | e | l | l | o | , | W | o | r | l | d | ! |
v%=INSTR("Hello, World!","o",7)
In this case v is assigned the value of 9 because the first occurance of "o" from position 7 is at position 9:
| ¯ | Start search here | |||||||||||
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| H | e | l | l | o | , | W | o | r | l | d | ! | |
Note. INSTR performs case-sensitive search. This meams that only in the case String1$ has the pefect match of String2$, the function will return a non-zero result:
p%=INSTR("Hello, World!","world")
In the above example, p is assigned the value of 0 because the word "world" isn't the part of "Hello, World!" just because of capitalization.
LCASE(x$)
Converts a string x$ to lowercase characters.
LCASE("Hello") ®
"hello"
LCASE("tHE") ®
"the"
LCASE("TITLE") ®
"title"
LEFT(a$,n)
Returns n left characters of string a$.
LEFT("Copyright",4) ®
"Copy"
LEFT("Sunflower",3) ®
"Sun"
a$=LEFT("animation",5)+"l"
In the above example the variable a$ is assigned the string "animal" because the function LEFT returns 5 first characters of "animation" which are "anima". Afterwards, the letter "l" is appended to the right producing the string "animal".
LEN(x$)
Counts the number of characters in the string x$.
LEN("Hi") ® 2
LEN("Hello, World!") ®
13
LEN("This is a long string") ®
21
LTRIM(x$)
Removes any leading spaces from a string. This function can be used to remove spaces from the user's input.
a$=LTRIM(" Hi")
Here a$ equals to "Hi".
MID(x$,n,m)
Returns m charcters of string x$, starting from position n. The last parameter m is optional. If it is omitted, the function returns the rest of the string after the character number n. The function counts every charcter including spaces.
MID("This is a long string",6,2) ® "is"
MID("Hello, World",8) ®
"World"
The keyword MID has another usage - as an assignment operator with the following syntax:
MID(x$,n,m)=y$
This statement replaces m characters of string x$ starting from position n with the string y$. Here x$ must be a variable name, not a string constant or expression. If the length of y$ is greater than m,only first m characters are used. If the length of y$ is less then m, only corresponding characters are replaced in x$, the others are intact.
You can also omit the third parameter (m) here. In this case the necessary number of characters are replaced (their number equals to the lenght of y$). If the lenght of x$ is less than needed to accomodate all characters from y$, the extra characters are ignored.
a$="I love you!" MID$(a$,8,3)="her"
After executing these lines, the variable a$ will equal to "I love her!".
MyString$="This is a test" MID(MyString$,11)="joker"
In the above example MyString$ will be changed to "This is a joke" because there's no room for the last character of "joker" - "r" in MyString$. If you need to increase the length of the string, append it with spaces first:
MyString$=MyString$+" " MID(MyString$,11)="joker"
This will yield MyString$="This is a joker"
RIGHT(x$,n)
Returns n right characters of string x$.
RIGHT("This is a test",4)®"test"
RTRIM(x$)
Removes any trailing spaces from the string x$.
SPACE(n)
Returns a string consisting of n space characters.
UCASE(x$)
Returns a string which is the same as x$ but each character is converted to uppercase.
FileName$="c:\MyDocuments\file.ext"
f$=UCASE(FileName$)
In the example, f$ will be "C:\MYDOCUMENTS\FILE.EXT"
On the next page you will learn about using CorelSCRIPT dialog boxes.