Jump to content

ReadFile from Point A to Point B


Recommended Posts

I have a text file as

 

[start]

This is a test

[/start]

 

 

 

How do I implement the fileread to read after [start] and before [/start]? I have not try it because I don't know where to begin with this.

Edited by Queener

Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")
Link to comment
Share on other sites

StringRegExp* or _StringBetween are your friends. :)

Please provide a more specific text file to adapt a solution.

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

I have some exam question/answers and are not allow to post or share... I'm just creating a question/answer problems for my own practice instead of wasting paper to print out. So it would look something like this:

 

[Question1]

Name: Q

Salary: $40 hourly / Bi Weekly

Status: Single

Debt: $250,000


Question 1: Will Q manage to afford a million dollar house?

[/Question1]

[Answer1]

A1=No

A2=Yes

A3=None of the above

[/Answer1]

 

 

Because there are return spaces, iniread is no longer a choice for me.

Edited by Queener

Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")
Link to comment
Share on other sites

You mean something like this here?

$sFileread =    "[Question1]" & @CRLF & @CRLF & _
                "Name: Q" & @CRLF & @CRLF & _
                "Salary: $40 hourly / Bi Weekly" & @CRLF & @CRLF & _
                "Status: Single" & @CRLF & @CRLF & _
                "Debt: $250,000" & @CRLF & @CRLF & @CRLF & _
                "Question 1: Will Q manage to afford a million dollar house?" & @CRLF & @CRLF & _
                "[/Question1]" & @CRLF & @CRLF & _
                "[Answer1]" & @CRLF & @CRLF & _
                "A1=No" & @CRLF & @CRLF & _
                "A2=Yes" & @CRLF & @CRLF & _
                "A3=None of the above" & @CRLF & @CRLF & _
                "[/Answer1]"

ConsoleWrite(StringRegExpReplace($sFileread, "[^\S]*[\[.*\]].*", "") & @CRLF)

 

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

I was hoping for something easier like read anything below [Question1] and stop reading before [/Question1] like so.

 

So the outcome should spit only

 

Name: Q

Salary: $40 hourly / Bi Weekly

Status: Single

Debt: $250,000


Question 1: Will Q manage to afford a million dollar house?

 

onto an editbox.

Edited by Queener

Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")
Link to comment
Share on other sites

You could use this concept to build the needed func   :)

$sFileread =    "[Question1]" & @CRLF & @CRLF & _
                "Name: Q" & @CRLF & @CRLF & _
                "Salary: $40 hourly / Bi Weekly" & @CRLF & @CRLF & _
                "Status: Single" & @CRLF & @CRLF & _
                "Debt: $250,000" & @CRLF & @CRLF & @CRLF & _
                "Question 1: Will Q manage to afford a million dollar house?" & @CRLF & @CRLF & _
                "[/Question1]" & @CRLF & @CRLF & _
                "[Answer1]" & @CRLF & @CRLF & _
                "A1=No" & @CRLF & @CRLF & _
                "A2=Yes" & @CRLF & @CRLF & _
                "A3=None of the above" & @CRLF & @CRLF & _
                "[/Answer1]"

$var1 = "Question1"

$res = StringStripWS(StringRegExp($sFileread, '\[' & $var1 & '\]\R+([^[]+)', 3)[0], 4)
Msgbox(0, $var1, $res)

$var2 = "Answer1"

$res = StringStripWS(StringRegExp($sFileread, '\[' & $var2 & '\]\R+([^[]+)', 3)[0], 4)
Msgbox(0, $var2, $res)

 

Link to comment
Share on other sites

Excuse my fart-mind. Thats exactly what I'm looking for. Thanks UEZ and mikell.

Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...