• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM [Solved] How to get the string between commas?

M

Matheus Carvalho

Guest
For example, I have:

0,1,12,11,23,10

How can I use "repeat(5)", and return the numbers between commas?

Right now I'm using "string_digits" and "string_char_at", but it doesn't work for numbers over 9, because for 10 it would detect 1 and 0.

I have a specific amount of numbers, lets say it's '100', so what I want is the easiest way to find these 100 numbers that are separeted by commas.
 
D

Dengar

Guest
string parsing :)
and this should work for the repeat() statement regardless of how long it is. its just a start, but the rest should be easy
Code:
input_string = "0,4,5,20,11,68,";
repeat(string_count(",",input_string))
{
//
}
 

jo-thijs

Member
Try this:
Code:
var result, n = 0;
var p, s = "0,1,12,11,23,10";
while s != "" {
    p = string_pos(",", s);
    if p == 0
        p = string_length(s) + 1;
    result[n++] = real(string_copy(s, 1, p - 1));
    s = string_delete(s, 1, p);
}
The temporary variable "result" will be an array of size n, containing the numbers represented in the string s.

EDIT: Fixed a slight mistake.
 
Top