I want to pick a word from a text file.

  • Suppose my text file has "Hi my name is [myname]."

    now i want to pick the word which is covering by the "[]" bracket.

    I use File Reader plugin to read the text file and Advance text box to show the data on construct 2.

    If someone know how can i do it please help me...

  • do a search on Regex in the manual.. there are a bunch of functions to help you process a string..

  • you cand do that by calling in the text, the word after a [comma] or a [dot] or a [-] and the text automatically will read the next word, had a capx of that is really simple thing actually! let me find it and will give it to you

  • RegexMatchAt(yourstring,"Hi my name is [(\w+)\]\.","i",1) (only works when it's one word, no spaces)

    RegexMatchAt(yourstring,"Hi my name is [([\w ]+)\]\.","i",1) (spaces are allowed)

    RegexMatchAt(yourstring,"Hi my name is [(.+)\]\.","i",1) (any characters are allowed, must be at least one character)

    one of these should do the job, depending on what you need

  • RegexMatchAt(yourstring,"Hi my name is [(\w+)\]\.","i",1) (only works when it's one word, no spaces)

    RegexMatchAt(yourstring,"Hi my name is [([\w ]+)\]\.","i",1) (spaces are allowed)

    RegexMatchAt(yourstring,"Hi my name is [([\w ]+)\]\.","i",1) (any characters are allowed, must be at least one character)

    one of these should do the job, depending on what you need

    if you give me a sample capx file it will be very helpful for me.

    @mindfaQ

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • you cand do that by calling in the text, the word after a [comma] or a [dot] or a [-] and the text automatically will read the next word, had a capx of that is really simple thing actually! let me find it and will give it to you

    waiting for the capx. please send me it

  • I won't post a capx, it's a basic system expression - go through the very basic tutorials, if you don't know how to use those.

  • I also waiting capx

    seriously

    ...le'ts say i have Unknow Text :

    "unknown text unknown [my 9name$] text unknown unknown length text unknown text unknown text unknown length !"

    how simple extract string between brackets?

    (in one action)

    ..i can find "[" & "]" and then extract string between brackets...

    or use something like

    RegexMatchAt(UnknownText.Text, "[[^\(\r\n]*\]", "g", 0) and then cut the brackets...

    but I can not figure out..how extract string between brackets...in one action

  • Ok bro.

    i set the Expressions on a Text object (as set text) : RegexMatchAt(AdvancedTextBox.Text,"[[(\w+)\]]\.","i",1)

    and add "[[word]]" on my txt file.

    but when i load my text file it it set nothing on the Text

    @mindfaQ

  • Of course like always with regex the necessary complexity depends on the data you can expect / want to work with.

    If the string always looks like "Hi my name is [myname].", a simple RegexMatchAt(AdvancedTextBox.Text,"Hi my name is [(.+)\]\.","i",1) or even RegexMatchAt(AdvancedTextBox.Text,"[(.+)\]\","i",1) will work.

    If you expect multiple [] in the text and you want to match them all plus wanna filter out newlines, it could look like this:

    https://copy.com/rITBhCmSQaOU7RCN

  • Thanks mindfaQ !

    this is what I was looking for:

    RegexMatchAt(RegexMatchAt(UnknownTexT.Text,"[([^\]\r\n]+)\]","gi",0),"[([^\]]+)\]","i",1)

    I was so close

  • Of course like always with regex the necessary complexity depends on the data you can expect / want to work with.

    If the string always looks like "Hi my name is [myname].", a simple RegexMatchAt(AdvancedTextBox.Text,"Hi my name is [(.+)\]\.","i",1) or even RegexMatchAt(AdvancedTextBox.Text,"[(.+)\]\","i",1) will work.

    If you expect multiple [] in the text and you want to match them all plus wanna filter out newlines, it could look like this:

    thanks a lot bro

  • nice if you solved it was the RegexMatchAt(RegexMatchAt(UnknownTexT.Text,"[([^\]\r\n]+)\]","gi",0),"[([^\]]+)\]","i",1) thing forgot to mention )

  • mindfaQ bro. now i'm facing another problem. I try to compare the value ( which i get from RegexMatchAt(RegexMatchAt(UnknownTexT.Text,"[([^\]\r\n]+)\]","gi",0),"[([^\]]+)\]","i",1) ) with another value.

    if the the values are equal it trigger another object to Visible .

    but it dont work.

    Here is my event sheet system:

    At first i add File Reader to read a text file (Set text Text bOx)

    then i use the expression to get data from the Text Box and set the data to Text1.

    I add Dictionary key "test" with value "myname"

    after that i compare the Text1 data with with the dictionary key value as trigger to visible the textbox.

    but do not work.

    can you help me to solve it?

  • Guys I need sample capx for this one. Pleaseeee..

    I type the word in textbox and it will search the result in text file

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