Skip to content

string_copy

CryoEagle edited this page Dec 26, 2018 · 5 revisions

string_copy

Returns all or part of another string.

Syntax:

string_copy(str, index, count)
Argument Description
string str The string to copy from
int index The position of the first character in the string to copy from (numbered from 1)
int count (Optional) The number of characters, starting from the position of the first, to copy

Returns: string

Description

With this function you can easily select a number of characters from within a string to be copied to another one. The first character in a string is always numbered as "1", so to copy (for example) the first five characters of string you would have string_copy(str, 1, 5). In SGML, the third parameter is optional. Without it, the runner will only copy the index position character. A further example is provided below.

Example:

string name = keyboard_string;
if string_length(name) > 15 )
{
    keyboard_string = string_copy(name, 1, 15 );
}

The above code will allow the player to input a string through the keyboard which is then stored in the variable "name". This variable is then checked to see if it exceeds the maximum length of 15 characters and if it does, the keyboard_string is replaced by a 15 character copy of the "name" string. This effectively limits the player input to 15 characters.

Back to strings

Clone this wiki locally