Solved

Replace text

Posted on 2006-10-31
2
183 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
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…

920 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

16 Experts available now in Live!

Get 1:1 Help Now