We help IT Professionals succeed at work.

# Replace text

on
Medium Priority
218 Views
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

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

i
Comment
Watch Question

## View Solutions Only

SQL Server Data Dude
CERTIFIED EXPERT
Most Valuable Expert 2013
Author of the Year 2015
Commented:
YourString = Replace(YourString, "45", "A1")
YourString = Replace(YourString, "45", "A11")
YourString = Replace(YourString, "51", "A2")
YourString = Replace(YourString, "51", "A22")

etc.

Not the solution you were looking for? Getting a personalized solution is easy.

High School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
CERTIFIED EXPERT
Top Expert 2009
Commented:
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
End If
##### Thanks for using Experts Exchange.

• View three pieces of content (articles, solutions, posts, and videos)
• Ask the experts questions (counted toward content limit)
• Customize your dashboard and profile