SolvedRemove Number Sequence

Posts 1–13 of 13 · Page 1 of 1
Remove Number Sequence
Ok so I wasn't sure where to ask this but I guess there may be a program that can help me, I have a txt file with a url in each line. Over 37,000 of them. Like this

1. www.blablabl.com
2. www.moreblabla.com
3. www.bla.com
37238. www.blabla.com

Im trying to find a way to remove each number and fall stop for everyline, I would imagine there is a simple way to do it but for the life of me I can't figure out a way. Any ideas?
do they all end in .com
Quote Originally Posted by Pingo View Post
do they all end in .com
some of them yes but alot are different, there must be a way to do it I just want to get rid of the numbers and fallstop after the number so im left with just the urls/links :/
Quote Originally Posted by silentrunner2 View Post
some of them yes but alot are different, there must be a way to do it I just want to get rid of the numbers and fallstop after the number so im left with just the urls/links :/
I'll put together something for ya.
Best way: Regex.

Another way, split by "." ->

dim lines() as String = System.Text.RegularExpressions.Regex.Split(fullTex t,"\n")
dim newText as string = ""

for i = 0 to lines.count - 1
dim split as string = lines(i).split(".")(0)
dim line as string = lines(i).substring(split.length+2,lines(i).length - split.length-2)
newText &= line & vbnewline
next

Noob way, but no further time to post a better one.
Enum list and check?

Or, I got this wrong :S
Code:
 Public Function deleteNumbers(ByVal Input As String) as string
        Dim lines() As String = System.Text.RegularExpressions.Regex.Split(Input, "\n")
        Dim sB As New System.Text.StringBuilder

        For i = 0 To lines.count - 1
            Dim split As String = lines(i).split(".")(0)
            Dim line As String = lines(i).substring(split.Length + 2, lines(i).length - split.Length - 2)
            sB.AppendLine(line)
        Next

        Return sB.ToString
    End Function
Code:
using sR as new system****.streamreader("yourfile.txt")
dim newText as string = deleteNumbers(sR.readtoend)

using sW as new system****.streamwriter("updated.txt")
sW.write(newText)
end using
end using

Way better method...

Code:
  Public Function delNumbers(ByVal Input As String)
        Return System.Text.RegularExpressions.Regex.Replace(Input, "\d+. ", "")
    End Function
@Blubb1337
ArgumentOutOfRangeException is what i get.
Plus Dim lines() As String is an array but your for loop is treating it as a list. It should be lines.Length not count.

Anyhoo
@silentrunner2
Heres what iv come up with. It reads it as one big string. Tested it on a text file 300,000 plus lines. Really fast on my system.

It will replace your original text file so backup the file before you try if you decide to use this method.

Code:
Imports System.[IO]
Code:
        Dim Opn As New OpenFileDialog
        If Opn.ShowDialog = DialogResult.OK Then
            Dim SR As New StreamReader(Opn.FileName)
            Dim tmp As String = SR.ReadToEnd
            Dim tmpPath As String = Path.GetTempFileName
            Dim SW As New StreamWriter(tmpPath)
            SR.Close()
            Dim i As Integer = 0, j = tmp.Length, _End
            Do
                i = tmp.IndexOf("www", i)
                If i <> -1 Then
                    _End = tmp.Substring(i, If((j - i > 30), 30, j - i)).IndexOf(ChrW(10))
                    If _End <> -1 Then
                        SW.WriteLine(tmp.Substring(i, _End))
                    End If
                    i += 1
                End If
            Loop Until i = -1
            SW.Close()
            File.Delete(Opn.FileName)
            File.Move(tmpPath, Opn.FileName)
            MessageBox.Show("DONE")
        End If
So, no Number Enum Check then?
(Don't know how It would be make in VB.Net)
Quote Originally Posted by Jorndel View Post
So, no Number Enum Check then?
(Don't know how It would be make in VB.Net)
Just shut your cunt and let the real men handle it.

Simple way:

Code:
Public Shared Sub FormatFile(ByVal inputFile As String, ByVal outputFile As String) 
   Using sReader As New IO.StreamReader(inputFile)
       Using sWriter As New IO.StreamWriter(outputFile)
           Dim line As String = String.Empty
           Dim sections As String()
           While Not sReader.EndOfStream
               line = sReader.ReadLine()
               sections = line.Split(New Char() {" "c}, 2)
               sWriter.WriteLine(CType(If(sections.Length = 2, sections(1), sections(0)), String))
           End While
       End Using
   End Using
End Function
Call it like so:
Code:
FormatFile("B:\fuckedformatting.txt", "B:\niceformatting.txt")
Or if you want to be a shitcunt and not worry about memory:

Code:
Dim original As String() = IO.File.ReadAllLines("yourfile")
IO.File.WriteAllLines("yourfile", Array.ConvertAll(original, Function(s) s.Split(New Char() { " "c }, 2)(1)))
Or use the above code to manipulate the text in memory. Either way.
Code:
Private Shared Function ExtractSitesFromFile(Filename As String) As List(Of String)
	Dim TempList As New List(Of String)()
	Dim Data As String = System.I O.File.ReadAllText(Filename)
	For Each NextURL As Match In Regex.Matches(Data, "(?<=.*?)www.*")
		TempList.Add(NextURL.Value)
	Next
	Return TempList
End Function
Private Shared Function ExtractSitesFromText(Source As String) As List(Of String)
	Dim TempList As New List(Of String)()
	For Each NextURL As Match In Regex.Matches(Source, "(?<=.*?)www.*")
		TempList.Add(NextURL.Value)
	Next
	Return TempList
End Function
You can use the above methods like this:

Code:
For Each Line As String In ExtractSitesFromFile(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\Data.txt")
	'MsgBox(Line) -- Display the line.
Next
Quote Originally Posted by Jason View Post


Just shut your cunt and let the real men handle it.

Simple way:

Code:
Public Shared Sub FormatFile(ByVal inputFile As String, ByVal outputFile As String) 
   Using sReader As New IO.StreamReader(inputFile)
       Using sWriter As New IO.StreamWriter(outputFile)
           Dim line As String = String.Empty
           Dim sections As String()
           While Not sReader.EndOfStream
               line = sReader.ReadLine()
               sections = line.Split(New Char() {" "c}, 2)
               sWriter.WriteLine(CType(If(sections.Length = 2, sections(1), sections(0)), String))
           End While
       End Using
   End Using
End Function
Call it like so:
Code:
FormatFile("B:\fuckedformatting.txt", "B:\niceformatting.txt")
Or if you want to be a shitcunt and not worry about memory:

Code:
Dim original As String() = IO.File.ReadAllLines("yourfile")
IO.File.WriteAllLines("yourfile", Array.ConvertAll(original, Function(s) s.Split(New Char() { " "c }, 2)(1)))
Or use the above code to manipulate the text in memory. Either way.
worked like a charm, thanks a bunch
Marked Solved. No more posting !
Posts 1–13 of 13 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?