Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 197
  • Last Modified:

Replace text

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
moto_sys
Asked:
moto_sys
2 Solutions
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
YourString = Replace(YourString, "45", "A1")
YourString = Replace(YourString, "45", "A11")
YourString = Replace(YourString, "51", "A2")
YourString = Replace(YourString, "51", "A22")

etc.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now