WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: MW4 on January 09, 2018, 04:00:17 PM

Title: Stuck on a StrReplace?
Post by: MW4 on January 09, 2018, 04:00:17 PM
I have a text file that I loop through one line at a time
I want to find the word "Contact" and delete everything from "Contact" on in that line
Then I'll write to a different named "fixed" file.

I am stuck thinking about how to handle it, maybe a StrReplace?

Here is some example data pre and post of what I'd like it to be.


Roof Type: N/A Contact
Roof Type: Standard Contact Name: Mike
Sales Type: Flood Contact
Sales Type: Flood Contact Name: Mike
Claim Date: 12/29/2017 8:32 PM CT Contact Fax:
Update Date Contact
Update Date Contact Email: Mike@Mike.com


Look for "Contact" & delete everything from "Contact" on in that line, Leaving this:


Roof Type: N/A
Roof Type: Standard
Sales Type: Flood
Sales Type: Flood
Claim Date: 12/29/2017 8:32 PM CT
Update Date
Update Date

I need a nudge in the right direction.  Thanks!!
Title: Re: Stuck on a StrReplace?
Post by: MW4 on January 09, 2018, 06:11:49 PM
Answered myself :)

      FoundIt = StrIndex(ThisLine, "Contact", 1, @FWDSCAN)
      
      If FoundIt == 0
         
      Else
         ThisLine = strsub(ThisLine, 1,FoundIt - 1)
      endif
Title: Re: Stuck on a StrReplace?
Post by: td on January 10, 2018, 07:19:06 AM
Another example of my favorite kind of question.