Jump to content

How To Find Text and Copy Text From That Point Backwards


 Share

Recommended Posts

Ok, I have a question, what steps are involved in making a script

1. Find Text

2. Highlight a Specified amount of lines up (not down)

3. Copy that text

4. Paste That text into a new document

5. Back to 1. but have step 4. paste at the bottom of the first text.

What I'm doing is trying to figure out what problems on a test Im getting right.

What it would do is find "1/1" (Which means I got it right) and copy upwards a few lines (perfectly would be up to the number of the problem) then paste it into a new document so I could have a list of exactly what problems I got right.

No need to make me a script just point me towards similar posts or to the right part of the help file

******************************Example*********************************

59

Marks: 1

Polar oceans, both N and S, existed during the

Choose one answer.

a. Middle Silurian

b. Middle Ordovician

c. Late Cambrian

Incorrect

Marks for this submission: 0/1.

60

Marks: 1

Proto-Pangea is called

Choose one answer.

a. Iapetus

b. Rodinia

c. Laurentia

d. Gondwanaland

Incorrect

Marks for this submission: 1/1.

61

Marks: 1

Reconstruction of the continents during the Paleozoic is accomplished by combining all but which of the following data?

Choose one answer.

a. paleomagnetic

b. paleoclimatic

c. bio-geographic

d. tectonic

e. all are relevant

Incorrect

Marks for this submission: 0/1.

Link to comment
Share on other sites

#include<Array.au3>
#include<File.au3>

Dim $fileArray
Dim $output = ""

;Read text file to array
_FileReadToArray("test.txt", $fileArray)

;Loop through entire array
For $X = 1 to $fileArray[0]
    
    ;Copy each line into temporary buffer
    $output &= $fileArray[$X] & @CRLF
    
    ;Look for score line
    If StringInStr($fileArray[$X],"Marks for this submission:") Then
        $tempArray = StringSplit($fileArray[$X], ":")
        $score = StringTrimRight(StringTrimLeft($tempArray[2], 1), 1)
        If $score = "1/1" Then
            ;Copy buffer to new file
            FileWrite("output.txt", $output)
        EndIf
        
        ;Clear buffer
        $output = ""        
    EndIf
Next

Link to comment
Share on other sites

Wow, I was hoping for some help lol but your script is great thnx for the step by step details so i can try doing something like this for myself lol

Question what does

$tempArray = StringSplit($fileArray[$X], ":")

$score = StringTrimRight(StringTrimLeft($tempArray[2], 1), 1)

actually tell the script to do?? I know the trims trim right and left but whats the ":" mean and the [2] I'm not sure what it is

I messed with the [2], changed it to 3 and it gave an error changed it to 1 and it did the same as 2

I messed with the ":" and changed it to "submission" it gave nothing to the output and then "." gave nothing so they are pretty key items, just not sure exactly what they do

Is it saying that its gonna read everything after ":" and if it = "1/1" then its gonna report it?

Edited by RAMMRODD
Link to comment
Share on other sites

StringSplit takes a string and divides it by a delimiter.

So this line:

$tempArray = StringSplit($fileArray[$X], ":")

Takes:

"Marks for this submission: 0/1."

And gives an array (element [0] contains the number of elements):

[0] = 2

[1] = "Marks for this submission"

[2] = " 0/1."

Now you have to remove the leading space and the trailing period from the string to give you "0/1".

This could be easier with regular expressions but I am not very good with those.

Link to comment
Share on other sites

  • 3 weeks later...

Ok, I want to try something on my own...if i take the above script it exports the correct answers to the output file but the test has an image of a dot that isnt picked up by SELECT ALL so what do I need to study up on to make the script delete everything but the "a" answer (IE "a.paleomagnetic") I thought I was getting somewhere with diagnosing the script above but that was a bit ago and now dont know what I was thinking XD so please dont write this for me but point me towards something or even an example script would be great.

61

Marks: 1

Reconstruction of the continents during the Paleozoic is accomplished by combining all but which of the following data?

Choose one answer.

a. paleomagnetic

b. paleoclimatic

c. bio-geographic

d. tectonic

e. all are relevant

correct

Marks for this submission: 1/1.

Link to comment
Share on other sites

  • 2 months later...

I have no clue what you are talking about "image of a dot" ?? "SELECT ALL"??

Sorry this took so long RL stuff came up and just realized this post hadnt been replied too. The test shows which answer is right by placing an image of a circle indicating that it is right. I was wondering what would I have to learn about for the script to take the output from the script above and then copy the answer with the circle next to it along with the questions.

Example

56. 2+2=?

(image of circle here)a. 4

b.9

c.0

the image of the circle is actually an image so i could screen shot it and probably Pixelsearch for it but then how do i make the script copy from the image to the right and the question? Typing this made me realize this maybe a little over my head but if anyone knows pplz enlighten me

ps. the "SELECT ALL" was my way of trying to explain that using "SELECT ALL" to copy the test into the "test.txt" folder for the original script to read didnt pick up the image of the circle. So select all only copied the question and answers without the image indicating that the question was answered right.

Link to comment
Share on other sites

  • 2 weeks later...

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...