• Hey! Guest! The 36th GMC Jam will take place between February 27th, 12:00 UTC - March 2nd, 12:00 UTC. Why not join in! Click here to find out more!

GML split equation into numbers and operator

AkjoHD

Member
I want to split an equation into 3 sections. The first number, the second number and the operator itself.

Example:
Input (string_print) = print 10+15
num1 = 10
num2 = 15
op = "+"

Code:
eq = string_copy(string_print, 7, string_length(string_print)-6)
This is the code I use for getting everything after the "print ".
 

chamaeleon

Member
I want to split an equation into 3 sections. The first number, the second number and the operator itself.

Example:
Input (string_print) = print 10+15
num1 = 10
num2 = 15
op = "+"

Code:
eq = string_copy(string_print, 7, string_length(string_print)-6)
This is the code I use for getting everything after the "print ".
Use the string_pos function to find the offset of your operator and use string_copy in conjunction with that to extract the number values. I'm sure you realize at this point string functions are not GMS strong suit. You'll either painstakingly build it yourself using the barebones functionality, or search the marketplace for a suitable extension (perhaps a regular expression extension, if one exists that offer the required functionality and target platform support).
 

AkjoHD

Member
Use the string_pos function to find the offset of your operator and use string_copy in conjunction with that to extract the number values. I'm sure you realize at this point string functions are not GMS strong suit. You'll either painstakingly build it yourself using the barebones functionality, or search the marketplace for a suitable extension (perhaps a regular expression extension, if one exists that offer the required functionality and target platform support).
Thanks for the help! String functions are definitely not GMS strong suit but I still will try it out tomorrow.
 
Top