Author Topic: Stuck on a StrReplace?  (Read 435 times)

MW4

  • Full Member
  • ***
  • Posts: 156
Stuck on a StrReplace?
« 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!!

MW4

  • Full Member
  • ***
  • Posts: 156
Re: Stuck on a StrReplace?
« Reply #1 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

td

  • Tech Support
  • *****
  • Posts: 2499
    • WinBatch
Re: Stuck on a StrReplace?
« Reply #2 on: January 10, 2018, 07:19:06 am »
Another example of my favorite kind of question.
"Success is a lousy teacher. It seduces smart people into thinking they can't lose."
  - Bill Gates