How to remove the numbers from a file

vmandem
vmandem used Ask the Experts™
on
Hi, I have a file where I need to look for any mixed numbers repeating more than 6 times like for example: "123456" or "222333" or any combination of numbers but if it exceeds 6 numbers. The repeating numbers may exist any where in the file and I need to see if any exist and remove them from the file.

Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Hi,

You need to read the file and copy the content in string variable. Then you need to split that string with the delimiter and store it in string array. Now you need to loop that array and check for each value that how many time it is repeating in it and if number appears more than 6 times remove it from array. Once you check for all values then again create a string with the same delimiter from the array and store it in the file.

Hope it helps you.
Shahan AyyubSenior Software Engineer
Commented:
If your file has such kind of text:
fdasfasf 541254352
gfdsg 42342342
432432

i.e., numbers are seperate with a space

Module Module1
    Sub Main()
        Dim s As String = System.IO.File.ReadAllText("C:\abc.txt")
        s = System.Text.RegularExpressions.Regex.Replace(s, "\b\d{7,}\b", "")
        System.IO.File.WriteAllText("C:\new.txt", s)
    End Sub
End Module

else

Module Module1
    Sub Main()
        Dim s As String = System.IO.File.ReadAllText("C:\abc.txt")
        s = System.Text.RegularExpressions.Regex.Replace(s, "\d{7,}", "")
        System.IO.File.WriteAllText("C:\new.txt", s)
    End Sub
End Module


Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial