Jump to content

Recommended Posts

im trying to make a script to filter some text files which have a name and address this is what i have atm

$line = FileReadLine($file)
if StringInStr($line,"N:")  Then
StringSplit ($line, "A:")
msgbox(0,"asd",$line )



Some of the strings have N: infront of them they are the ones i want to split eg N:John Doe A:14576 Pea St


what i need to do is split the one string into two Name and Address thn output them which im going to do later

This is what i want the output to look like

John Doe

14576 Pea St

hope i explained that good :S


Edited by BladeZ
Link to post
Share on other sites
  • Moderators

Here this might do the trick:

#include <file.au3>

Local $File2Open = FileOpenDialog('Find Address Book', @ScriptDir, 'All Files (*.*)')
Local $OutPutFile = StringTrimRight($File2Open, 4) & '_Syntaxed.txt'
Local $nArray
Local $Name
Local $Address
Local $OutPut
_FileReadToArray($File2Open, $nArray)

For $i = 1 To UBound($nArray) - 1
    If StringInStr($nArray[$i], 'N:') And StringInStr($nArray[$i], 'A:') Then
        $Name = StringStripWS(_StringBetween($nArray[$i], 'N:', 'A:'), 7)
        $Address = StringStripWS(StringTrimLeft($nArray[$i], StringInStr($nArray[$i], 'A:') + 1), 7)
        $OutPut = $OutPut & $Name & @CRLF & $Address & Chr(01)

Local $WriteOutPut = StringSplit(StringTrimRight($OutPut, 1), Chr(01))

For $x = 1 To UBound($WriteOutPut) - 1
    FileWriteLine($OutPutFile, $WriteOutPut[$x] & @CRLF & @CRLF)
Func _StringBetween($s_String, $s_Start, $s_End = 0)
    $s_Start = StringInStr($s_String, $s_Start)+StringLen($s_Start)
    return StringMid($s_String, $s_Start, StringInStr($s_String, $s_End)-$s_Start)

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...