Jump to content

Problem with String Splits: Unwantend Spaces


Recommended Posts

Hi,

i have a data email.txt containing infos in the format emailaddress:name. My Script reads all lines, splits them on the : and put them into two arrays. Then it splits the email to get the domain name the emailaddress is registered on and saves email:name in a new text data named *emaildomain*.txt. The list i start with has over 22.000 entrys, and it takes some time. But than the script gives me an error that it cant open "*emaildomain* .txt" (watch the space). First i thought this is because of the input data, but when i opened the email.txt with the notepad and searched for " " it doesnt found anything, so it must be an error in my script or something else. I already tried to replace all spaces in the temporarily data after reading from the source, but this doenst solve the problem.

Heres the script:

#include <String.au3>
#include <array.au3>

;Verbessern: Evtl. Leerzeichen ersetzen!

; Emailliste laden
$file = FileOpen("email.txt", 0)

If $file = -1 Then
    MsgBox(0, "Fehler", "Die Datei email.txt konnte nicht geöffnet werden!")
    Exit
EndIf

; Emails zählen

$i = 1

While 1
    $line = FileReadLine($file, $i)
    If @error = -1 Then ExitLoop
    $i+=1
Wend

; Email Array erstellen
Dim $email[$i-1]
Dim $name[$i-1]

; Email Array füllen
$i2 = 1
Dim $linearray[2]

While $i2 < $i
    $line = FileReadLine($file, $i2)
    If @error = -1 Then
        ExitLoop
    Endif
    $linearray = StringSplit($line, ":")
    If $linearray[0] = 2 Then
    $linearray[2] = StringReplace ($linearray[2], " ", "")
    $email[$i2-1] = $linearray[1]
    $name[$i2-1] = $linearray[2]
    Endif
    $i2+=1
Wend

FileClose($file)

;_ArrayDisplay($email, "Emails")

$i2 = 1

; Emails splitten und abspeichern

While $i2 < $i
    $linearray = StringSplit($email[$i2-1], "@")
;_ArrayDisplay($linearray, "Emails")
    If $linearray[0] = 2 Then
        $file = FileOpen("u_" & $linearray[2] & ".txt", 1)
        If $file = -1 Then
            MsgBox(0, "Fehler", "Die Datei u_" & $linearray[2] & ".txt konnte nicht geöffnet werden!")
            Exit
        EndIf
        FileWriteLine($file, $email[$i2-1] & ":" & $name[$i2-1])
        FileClose($file)
    EndIf
    $i2+=1
Wend

Maybe someone can take a look on this...

Thank you in advance.

Regards, Carny

Link to comment
Share on other sites

  • Developers

You will have to give the input file containg a few test reocord that makes the script fail to be able to test.

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...