Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Search and Replace text

Guest
Mar 28, 2014 Mar 28, 2014

Apologies for what is no doubt a simple question - I'm trying to help out IT and I'm not a programmer, although maybe one day...

Anyway, I'm going to need to read a text file, and search for a string in that text file and replace it.  I see "replace" as a function but I'm not familiar with how to use it.  Poking around I found <cffile action=append> and used that to add a line to a text document.  (Just a notepad .txt)

Ultimately I'll need to unzip a folder, search and replace the string in a specific file in there, and then re-zip the file, but we'll get to that later.  I managed to unzip a folder already, that's easy enough.  Putting it all together is my current challenge.

I'm using ColdFusion Builder 2.0

Thanks for any help you guys can give.

1.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Mar 28, 2014 Mar 28, 2014

file.txt: Contains several lines that all say "All Work And No Play Makes Jack A Dull Boy".

<cffile action="read" file="C:\file.txt" variable="myFile">

<cfset myFile = Replace(myFile,"Dull","Bored","all")>

<cffile action="write" file="C:\file.txt" output="#myFile#" addnewline="no" fixnewline="no">

<cffile action="read" file="C:\file.txt" variable="myNewFile">

<cfoutput>#myNewFile#</cfoutput>

^_^

Translate
LEGEND ,
Mar 28, 2014 Mar 28, 2014

file.txt: Contains several lines that all say "All Work And No Play Makes Jack A Dull Boy".

<cffile action="read" file="C:\file.txt" variable="myFile">

<cfset myFile = Replace(myFile,"Dull","Bored","all")>

<cffile action="write" file="C:\file.txt" output="#myFile#" addnewline="no" fixnewline="no">

<cffile action="read" file="C:\file.txt" variable="myNewFile">

<cfoutput>#myNewFile#</cfoutput>

^_^

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 28, 2014 Mar 28, 2014

Very groovy.  Thanks!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 28, 2014 Mar 28, 2014

You're welcome.  Thanks for marking my response as correct.  Have a great weekend.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 29, 2014 Mar 29, 2014
LATEST

You might want to ignore case-sensitivity. If so, you should use instead

<cfset myFile = replaceNoCase(myFile,"Dull","Bored","all")>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources