Jump to content
Sign in to follow this  
Carny

Problem with String Splits: Unwantend Spaces

Recommended Posts

Carny

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

Share this post


Link to post
Share on other sites
Jos

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


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
weaponx

Instead of using FileReadLine() I would just do:

#include <file.au3>

Dim $myArray

_FileReadToArray("email.txt", $myArray)

For $X = 1 to $myArray[0]

...

Next

Share this post


Link to post
Share on other sites
zorphnog

^What he said. Your current method iterates through the file twice, which = 2x longer execution. Also, try using:

$linearray[2] = StringStripWS ($linearray[2], 8)oÝ÷ Ú)駡ö®¶­sbb33c¶ÆæV'&³%ÒÒ7G&æu&WÆ6Rb33c¶ÆæV'&³%ÒÂgV÷C²gV÷C²ÂgV÷C²gV÷C²

Share this post


Link to post
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
Sign in to follow this  

×