Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 230575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:51:39+00:00 2026-05-11T19:51:39+00:00

For a given set of text files, I need to find every \ character

  • 0

For a given set of text files, I need to find every “\” character and replace it with “\\“. This is a Windows system, and my scripting language options are Javascript, VBScript, or Perl.

These files are largish (~10MB a piece), and there are a good number of them (~15,000). I’ve already come up with the following Javascript:

function EscapeSlashes(inFilePath)
{
    var readOnly = 1;
    var fso  = WScript.CreateObject("Scripting.FileSystemObject");
    var outFile = fso.CreateTextFile(inFilePath + "escaped.js", true);
    var inFile = fso.OpenTextFile(inFilePath, readOnly);

    var currChar;
    while(!inFile.AtEndOfStream)
    {
        currChar = inFile.Read(1);

        //check for single backslash
        if(currChar != "\\")
        {
            outFile.Write(currChar);
        }
        else
        {
            //write out a double backslash
            outFile.Write("\\\\");
        }
    }

    outFile.Close();
    inFile.Close();
}

I’m worried that the above might be a bit slow. Is there any way to improve the algorithm? Since I’m replacing one character with two, I don’t think this can be done in-place.

Is there any performance advantage to reading line by line, rather than character by character?

Do Perl or VBScript have any advantages over Javascript in this case?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T19:51:39+00:00Added an answer on May 11, 2026 at 7:51 pm

    You can’t do it in place, but generally it’s a good idea to read data in chunks rather than reading a single value at a time. Read a chunk, and then iterate through it. Read another chunk, etc – until the “chunk” is of length 0, or however the call to Read indicates the end of the stream. (On most platforms the call to Read can indicate that rather than you having to call a separate AtEndOfStream function.)

    Also, I wouldn’t be surprised if Perl could do this in a single line. Or use sed if you can 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey guys, given a data set in plain text such as the following: ==Events==
This is one of the solution of getting true or false from given set
Given a set of questions that have linked survey and category id: > db.questions.find().toArray();
Given all the complex things I seem to cover every day, this appears to
I'm manipulating text files and need to build a perl script to run a
I have a set of 1000 text files with names in_s1.txt , in_s2.txt and
Is there any way of automating a site publish with a given set of
I can see that Collections.unmodifiableSet returns an unmodifiable view of the given set but
Given a set of phrases, i would like to filter the set of all
Given a set Paris New York London New York Paris Paris I'm trying to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.