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 1109507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:14:47+00:00 2026-05-17T02:14:47+00:00

I’m trying to insert a string that begins with the word title as in

  • 0

I’m trying to insert a string that begins with the word title as in title: New string to be inserted
into a file that has the following format. A bunch of text at the top, a block of lines each beginning with the word title:, and a bunch of text at the bottom.

Some content here at the top 
And more content 
and the titles will begin next

title: Basic String
title: How does it evaluate strings
title: Identify code links
title: Translating vbscript to string

some content at the bottom
and more content at the bottom

The thing is I’d prefer to insert that new string title: New string to be inserted so that it’s organized alphabetically in the block of titles to make it easier to maintain this file. How can I do this with vbscript. I discovered it a few hours ago and think it’s a great alternative for what I’m trying to do, but not that great at it yet, so any help would be great

How would I loop through all lines of
the file, copy each line to a new
file, until I hit a title that is
alphabetically after my title, add my
title to the new file at that spot,
then copy the rest of the file to the
new file and close.

Because I’m poor in vbscript syntax, I can only think of a pseudo algorithm,

Loop to read through all lines
  If the line does not start with the word title:, copy it as is into the new file
  If the line starts with the word title, remove the `title:` sub-string, then check if it is alphabetically before or after my title
      If before my title, copy it into the new file
      If after my title, then copy my title there, and copy all rest of the file as is, and EXIT
End loop
  • 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-17T02:14:47+00:00Added an answer on May 17, 2026 at 2:14 am

    There’s no easy way to sort in vbscript. You have to do your own sort subroutine. Here’s a little cheating using the windows cmd sort.

    strToInsert= WScript.Arguments(0)
    strFileName = WScript.Arguments(1)
    Set objFS = CreateObject( "Scripting.FileSystemObject" )
    If objFS.FileExists("temp") Then
      objFS.DeleteFile("temp")
    End If 
    Set objRE = New RegExp
    objRE.IgnoreCase = False
    objRE.Pattern = "^title.*"
    Set objFile = objFS.OpenTextFile(strFileName)
    Set objOutFile = objFS.OpenTextFile("temp",2 , True )
    Dim A()
    d=0
    Do Until objFile.AtEndOfStream    
        linenum=objFile.Line
        strLine = objFile.ReadLine
        Set Matches = objRE.Execute(strLine)
        For Each Match in Matches   ' Iterate Matches collection.             
            objOutFile.Write(Match.Value & vbCrLf)
            ReDim Preserve A(d)
            A(d)=linenum ' get position of title lines
            d=d+1
        Next    
    Loop       
    objOutFile.Write(strToInsert & vbCrLf)
    objFile.Close
    objOutFile.Close
    
    Set WshShell = CreateObject("WScript.Shell")
    Set objFile = objFS.OpenTextFile(strFileName)
    Do Until objFile.AtEndOfStream  
        linenum=objFile.Line  
        strLine = objFile.ReadLine
        c=0 
        If linenum =  A(0) Then
            Set oExec = WshShell.Exec("sort temp ")
            Do While Not oExec.StdOut.AtEndOfStream
                  sLine = oExec.StdOut.ReadLine
                  WScript.Echo sLine
                  c=c+1
            Loop
            oExec.Terminate 
        End If 
        If linenum <A(0) Or linenum > A(UBound(A)) Then
            WScript.Echo strLine
        End If 
    Loop  
    

    Output

    C:\test>cscript //nologo  myscript.vbs "title: to insert new string" file
    Some content here at the top
    And more content
    and the titles will begin next
    
    title: Basic String
    title: How does it evaluate strings
    title: Identify code links
    title: to insert new string
    title: Translating vbscript to string
    
    some content at the bottom
    and more content at the bottom
    

    If you want to do the sorting with vbscript, you can search stackoverflow for “vbscript sort arrays” and there are suggestions on how to do that.

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I have just tried to save a simple *.rtf file with some websites and
I am trying to loop through a bunch of documents I have to put

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.