Jump to content

Find a sentence and remove


Recommended Posts

I am looking for a way to search a text file for the start of a sentence

eg.

Tunnel command:

and

Command to run:

The beginning of each sentence begins the same. What would be the easiest way to accomplish this.

I will have more than just the two sentences.

BTW there could be multiple sentences that start the same way and I will need to remove them all.

Link to comment
Share on other sites

The best way would be to use the StringRegExp()or StringRegExpReplace() functions.

Unfortunately I am lousey at making patterns still, but it wont harm you to have a look, you will most likely be better at it than I.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

  • Moderators

You could use StringRegExpReplace but you need an ending character for the sentence ( like some type of punctuation ).

Example, if all your sentences end in a period:

Global $s_infile = "filename to read"
Global $s_outfile = "filename to write to, could be the same as in file"
Global $s_string = FileRead("filename")
$s_string = StringRegExpReplace($s_string, "(?i)(?s)Tunnel command:.+?\.", "")
$s_string = StringRegExpReplace($s_string, "(?i)(?s)Command to run:.+?\.", "")

Global $h_open = FileOpen($s_outfile, 2)
FileWrite($h_open, $s_string)
FileClose($h_open)

Be sure to use this code on a test file only.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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