How do I retreive specific part of a textfile?

0 favourites
  • 4 posts
From the Asset Store
Smart UI Part 1 by Epic Stock Media is a one-of-a-kind collection of modern user interface sound effects.
  • Hi! I am trying to retreive text from a txt file and display the content on the screen. I'm using AJAX to retreive the content of the .txt file and it works fine but I'm at a loss as for how to retreive a specific part of the textfile.

    Say my textfile look like this:


    01 text!

    02 another text!


    How can I retreive only the part that starts with 01 and stop reading after the exclamation mark?


  • Use a regex expression to do that:

    RegexMatchAt(AJAX.LastData, "01.*!", "", 0)

    Regex is very powerful and allows you to do a lot of cool text searching. ... xpressions

    This is the expression I used:


    What it does is:

    0 matches "0"

    1 matches "1"

    . matches anything

    * matches any number of the previous. Or in this case anything

    ! matches "!"

  • One way you could do it, is by removing the 01 and ! and just putting each message on a new line, then use the tokenat system expression with the delimiter being the newline thing (character?). Or, you could use a regex, in a general case, this regex would work: "[\d]+\s([\w\s]+\!)". For the purpose of extracting a string, if you know the number of the text you want, have that number stored, as a variable or parameter and then this regex would work: number & '\s([\w\s]+\!)'".

    So this: would always return the first regex match (text):

    However, this would allow you to specify the number:

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thanks R0J0hound, it works wonders and that link was very helpful!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)