string_copy

Returns all or part of another string.

Syntax:

GML Code Example

string_copy(str, index, count);


Argument Description
str The string to copy from.
index The position of the first character in the string to copy from (numbered from 1)
count 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). A further example is provided below.

Example:

GML Code Example

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: Strings



No Examples Submitted

Does this page need better examples? Be the first to Submit

No Edits Suggested

Is this page unclear or not descriptive enough? Suggest an edit to the page and with enough upvotes your changes will be made.

No Questions Have Been Ask

Do you have a question about this page? Ask it Here