1. 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!
    Dismiss Notice

GML only part of a string...

Discussion in 'Programming' started by Anomaly, Oct 7, 2017.

Tags:
  1. Anomaly

    Anomaly Member

    Joined:
    Aug 23, 2017
    Posts:
    244
    you know in file searching you can say... search: thisFile10_*.* and it will find any thing that begins with just "thisFile10_"
    is there a way to phrase strings in GM to achieve something similar?
     
  2. Simon Gust

    Simon Gust Member

    Joined:
    Nov 15, 2016
    Posts:
    3,258
    I believe get_open_filename and get_save_filename does that.
     
  3. Anomaly

    Anomaly Member

    Joined:
    Aug 23, 2017
    Posts:
    244
    Oh whoops
    Sorry I wasn't clear as to what I meant exactly...
    I meant in strings but NOT for files..

    Like var layervar = string "parallax_layer_1" + " * "
    Where * would be anything...
    And if I only have one thing that begins with " paralax_layer_1 "..it would use that.
     
  4. Homunculus

    Homunculus Member

    Joined:
    Jun 20, 2016
    Posts:
    856
    You can use string copy with the size of the string you are looking for. Example:

    Code:
    var starts_with = "parallax_layer_1";
    var count = string_length(starts_with);
    
    var str = string_copy(layervar,1,count);
    
    if(str == starts_with) {..do something..}
    Ideally you could turn this into a script so all you have to do is something like string_starts_with(layervar,"parallax_layer_1");
     
    Anomaly likes this.
  5. Anomaly

    Anomaly Member

    Joined:
    Aug 23, 2017
    Posts:
    244
    isn't there something where .. if "this" character in the string is the actual character "1" or "2" then so and so...
    was trying to find that command...
     
  6. IndianaBones

    IndianaBones Member

    Joined:
    Jul 5, 2016
    Posts:
    2,389
    string_pos() function is the closest to what you want.

    Code:
    var string_to_check = "thisFile10_abcdefg"
    var result = string_pos("thisFile10_", string_to_check)
    
    "result" will equal 0 if no matching string is found, or it will return the position the string begins at if it finds a match.

    So in the above code example, result will be 1. (strings start at position 1 in GMS)

    Manual : string_pos()
     
    Anomaly likes this.

Share This Page