1. Hey! Guest! The 35th GMC Jam will take place between November 28th, 12:00 UTC - December 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice

GML How to cut specific string from a text?

Discussion in 'Programming' started by Edwin, May 8, 2019.

Tags:
  1. Edwin

    Edwin Member

    Joined:
    Jul 15, 2018
    Posts:
    417
    Hello, people. Can you please tell me the way how to cut off a specific string from a text? For example to cut "World" from "Hello, World!".
     
  2. Ido-f

    Ido-f Member

    Joined:
    Feb 19, 2018
    Posts:
    125
    Code:
    new_string = string_copy(string, character to start copying from (first character's index is 1), numbers of characters to copy).
    You can use string_pos to find out the index of a character or a sub-string.
     
    Edwin likes this.
  3. Luke Norton

    Luke Norton Member

    Joined:
    Feb 26, 2019
    Posts:
    6
    Use the function string_delete().
    You need the name of the string, the position/index of the first character to remove (in this case, it would be 8) and the number of characters to remove, so 5.
     
    Edwin likes this.
  4. stainedofmind

    stainedofmind Member

    Joined:
    Jun 20, 2016
    Posts:
    701
    One liner:

    Code:
    new_string = string_replace_all(old_string, "World", "');
    
     
    Ido-f likes this.
  5. Edwin

    Edwin Member

    Joined:
    Jul 15, 2018
    Posts:
    417
    Thanks, totally forgot about this function, If you know, could you tell me how I can check what goes after tags in string so I can use and replace them? For example:
    Code:
    "[spoiler=This is spoiler] SPOILER [/spoiler]"
    
    I can use string_replace to replace , but anyway I need to get the string that goes after equal sign.
     
  6. Drepple

    Drepple Member

    Joined:
    Dec 9, 2017
    Posts:
    43
    Use string_pos(substr, str) to find the location of a substring in a string, so string_pos("=", str) would give you the position of the equal sign. I assume you don't want to replace the equal sign itself so use that position+1 for replacing, adding, deleting etc. I recommend you look at all the string functions here. Consulting the YoYo Games manual is probably the fastest way to figure out what your looking for / how a function works. Anyways, good luck with your project!
     
    Edwin likes this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice