Solved

Replace text

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Suggested Solutions

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

839 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