Add to Favorites    Make Home Page 772 Online  
 Language Categories  
 Our Services  

Home » ASP Home » Strings Home » Find and Replace

A D V E R T I S E M E N T

Search Projects & Source Codes:

Title Find and Replace
Description This will find all occurences of a string in a text file and replace it with another string. Multiple strings can be searched and replaced at the same time.
Parameters: [Filename] [String to search] [String to replace] [Comparison Method (optional)][
Category ASP » Strings
Hits 380155
Code Select and Copy the Code
Option Explicit Dim fso Dim folder Dim logfile Dim newfile Dim deletefile Dim finalcontents Dim objArgs Dim filename Dim searchstr Dim replacestr Dim CompareMethod Dim Counter Set objArgs = WScript.Arguments Set fso = CreateObject("Scripting.FileSystemObject") If objArgs.count >= 3 And objArgs.count <=4 Then filename = objArgs(0) searchstr = Split(objArgs(1),",") replacestr = Split(objArgs(2),",") If objArgs.count = 4 Then CompareMethod = objArgs(3) If CompareMethod <> 0 And CompareMethod <> 1 Then Wscript.Echo "CompareMethod can only be 0 or 1" Wscript.Quit(1) 'To indicate error. End If Else CompareMethod = 0 ' Default To vbBinaryCompare. End If Else wscript.echo "Usage: FindReplace.vbs [arguments..]" + vbCrLf + vbCrLf + "Arguments:" + vbCrLf + "File To be Searched" + vbCrLf + "Searched string" + vbCrLf + "String to replace" + vbCrLf + "[Comparison Method]" wscript.Quit (1) 'To indicate error. End If ' Check the length of search string and ' replace string. ' Both should be equal otherwise error o ' ut If UBound(searchstr) <> UBound(replacestr) Then wscript.echo "Search String does Not have corresponding replace string" wscript.Quit(1) End If TextSearch(Filename) Function TextSearch(Filename) Set logfile = fso.OpenTextFile(filename) If Err.number <> 0 Then Wscript.echo Err.description Wscript.Quit (Err.number) End If Counter = 0 finalcontents = logfile.readall Do While Counter <= UBound(searchstr) If CompareMethod = 0 Then finalcontents = Replace(finalcontents, Trim(searchstr(counter)), Trim(replacestr(counter)), 1, -1, vbBinaryCompare) Else finalcontents = Replace(finalcontents, Trim(searchstr(counter)), Trim(replacestr(counter)), 1, -1, vbTextCompare) End If Counter = counter + 1 Loop logfile.Close Set deletefile = fso.getFile(filename) deletefile.delete Set newfile = fso.CreateTextFile(filename, True) newfile.write FinalContents newfile.close If Err.number <> 0 Then Wscript.echo Err.description Wscript.Quit (Err.number) End If Set logfile = Nothing Set deletefile = Nothing Set newfile = Nothing End Function

Related Source Codes

Script Name Author
��������������������� VyomWorld
Resistor color code reader A.Chermarajan.
Telephone Directory dhivya
card swapping game (Mini Project) nityanand
simple hangman-pascalsource Seabert
college dirtectory (Mini Project) msridhar
Poll Application John van Meter
ASP Daily Hit Counter. Tejaskumar Gandhi
To avoid null in asp environment using sql Sami
Maklumbalas webmaster
poll John van Meter
EasyASP Template Engine. TjoekBezoer
Basic Calculator using HTML & Javascript. Patrick M. D Souza
What servers support ASP ? VyomWorld
What is ASP? VyomWorld

A D V E R T I S E M E N T




Google Groups Subscribe to SourceCodesWorld - Techies Talk
Email:

Free eBook - Interview Questions: Get over 1,000 Interview Questions in an eBook for free when you join JobsAssist. Just click on the button below to join JobsAssist and you will immediately receive the Free eBook with thousands of Interview Questions in an ebook when you join.

New! Click here to Add your Code!


ASP Home | C Home | C++ Home | COBOL Home | Java Home | Pascal Home
Source Codes Home Page

 Advertisements  

Google Search

Google

Source Codes World.com is a part of Vyom Network.

Vyom Network : Web Hosting | Dedicated Server | Free SMS, GRE, GMAT, MBA | Online Exams | Freshers Jobs | Software Downloads | Interview Questions | Jobs, Discussions | Placement Papers | Free eBooks | Free eBooks | Free Business Info | Interview Questions | Free Tutorials | Arabic, French, German | IAS Preparation | Jokes, Songs, Fun | Free Classifieds | Free Recipes | Free Downloads | Bangalore Info | Tech Solutions | Project Outsourcing, Web Hosting | GATE Preparation | MBA Preparation | SAP Info | Software Testing | Google Logo Maker | Freshers Jobs

Sitemap | Privacy Policy | Terms and Conditions | Important Websites
Copyright ©2003-2024 SourceCodesWorld.com, All Rights Reserved.
Page URL: http://www.sourcecodesworld.com/source/show.asp?ScriptID=185


Download Yahoo Messenger | Placement Papers | Free SMS | C Interview Questions | C++ Interview Questions | Quick2Host Review