Replace text

Posted on 2006-10-31
Last Modified: 2010-04-30
i have a text file with 100 lines

for example:


i want to replace all de 45,51,78,80,90
45 = A1,A11
51 = A2,A22
78 = A3,A33
80 = A4,A44
90 = A5,A55

but maybe need to be more than 5 could be 5 or more



Question by:moto_sys
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 66

Assisted Solution

by:Jim Horn
Jim Horn earned 50 total points
ID: 17844287
YourString = Replace(YourString, "45", "A1")
YourString = Replace(YourString, "45", "A11")
YourString = Replace(YourString, "51", "A2")
YourString = Replace(YourString, "51", "A22")

LVL 86

Accepted Solution

Mike Tomlinson earned 150 total points
ID: 17844361
The whole thing...

    Dim ff As Integer
    Dim entireFile As String
    Dim fileName As String

    fileName = "c:\someFile.txt"
    If Dir(fileName) <> "" Then
        ff = FreeFile
        Open fileName For Binary Access Read As #ff
        entireFile = Input(LOF(ff), ff)
        Close #ff
        entireFile = Replace(entireFile, "45", "A1,A11")
        entireFile = Replace(entireFile, "51", "A2,A22")
        entireFile = Replace(entireFile, "78", "A3,A33")
        entireFile = Replace(entireFile, "80", "A4,A44")
        entireFile = Replace(entireFile, "90", "A5,A55")
        ff = FreeFile
        Open fileName For Output As #ff
        Print #ff, entireFile
        Close #ff
        MsgBox fileName, vbCritical, "File not found"
    End If

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question