Solved

Replace text

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


for example:

aa,45,78,79,80,81,82,83,84,85,86,88,14
ab,22,80,99,56,84,85,86,89,12
ac,11,78,79,80,81,82,83,84,16,72,94,5,7,14
ad,58,78,79,80,81,82,83,84,85,86,88,14


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


Output

aa,A1,A11,A2,79,A4,A44,81,82,83,84,85,86,88,14
ab,22,80,99,56,84,85,86,89,12
ac,11,A3,A33,79,A4,A44,81,82,83,84,16,72,94,5,7,14
ad,58,A3,A33,79,A4,A44,81,82,83,84,85,86,88,14

i
0
Comment
Question by:moto_sys
2 Comments
 
LVL 65

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")

etc.
0
 
LVL 85

Accepted Solution

by:
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
    Else
        MsgBox fileName, vbCritical, "File not found"
    End If
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now