Pelican Police
Member
GM Version: 1.4
Target Platform: ALL
Download: string_digits_ext.gml
Links: N/A
Summary:
The built in function string_digits is useful if you want to extract a number from a string. But it overlooks the fact that numbers also use the characters " - " and " . " and still removes these. The script below does exactly what string_digits does, but also leaves in those extra characters.
Example:
built in:
this script:
Usage:
- Download from link above, and then drag "string_digits_ext.gml" over your project window, then select "script" from the popup.
or
- Copy paste this code directly into a new script in your project:
I hope this can be of use to you!
Some more keywords:
Decimal separator, digits, values, int, integer, minus, dash, point, removes, deletes,
Target Platform: ALL
Download: string_digits_ext.gml
Links: N/A
Summary:
The built in function string_digits is useful if you want to extract a number from a string. But it overlooks the fact that numbers also use the characters " - " and " . " and still removes these. The script below does exactly what string_digits does, but also leaves in those extra characters.
Example:
built in:
string_digits("Your score is -17.09");
gives "1709"this script:
string_digits_ext("Your score is -17.09");
gives "-17.09"Usage:
- Download from link above, and then drag "string_digits_ext.gml" over your project window, then select "script" from the popup.
or
- Copy paste this code directly into a new script in your project:
Code:
///string_digits_ext(str)
/*
Same as string_digits but also allows for . and -
*/
// Arguments
var str = argument0;
var newStr = ""; // The string we will return
// Loop for each char in the string
var i = 1;
repeat string_length(str)
{
// Retrieves the next char in the string (but as its ascii id)
var nextOrd = string_ord_at(str,i);
// If the char is from 0-9, is . or is -
// https://i.stack.imgur.com/bwCFl.gif (Char list)
if (nextOrd >= 48 and nextOrd <= 57) or nextOrd == 46 or nextOrd == 45
{
// Approve this character
newStr += chr(nextOrd); // (Convert ord to char).
}
i++;
}
// Return a string of approved characters
return newStr;
Some more keywords:
Decimal separator, digits, values, int, integer, minus, dash, point, removes, deletes,