Jump to content
Sign in to follow this  
polingkyle

Help Changing "Last First MI" to "First MI Last"

Recommended Posts

pokingkyle,

Without access to the EXACT file that you are processing we are only guessing!

kylomas

I posted the exact contents of the file that I'm processing today. The file changes everyday but the formatting stays the same. The contents that I posted in my second post are saved to a file on my desktop called MuniCourt.txt. Thanks.

Share this post


Link to post
Share on other sites

polingkyle,

In your origional script you were testing for crlf and cr. It is also common to find just lf (line feed). Can you download (upload?) a copy of the file that you are working with?

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

Alright folks. I have to sign off for awhile or my wife might leave me... :huh: I uploaded a copy of the exact text file that I'm working with. I truely appreciate all of the help. I'll try to integrate some of your ideas into my currect script to see if it does what I need it to. Thanks again!!

Kyle

Edited by Melba23
File removed

Share this post


Link to post
Share on other sites

array exaple

#include <String.au3>
#include <Array.au3>
#include <File.au3>
Dim $array
_FileReadToArray('data.txt',$array)
For $x = 1 To $array[0]
    If $array[$x] Then $array[$x] = _SomeFunc($array[$x])
Next
_FileWriteFromArray('new.txt',$array,1)

Func _SomeFunc($MainData)
    Local $first = StringSplit($MainData,',')
    If Not IsArray($first) Then Return $MainData
    Local $second = _StringExplode($first[1],' ',1)
    If Not IsArray($second) Then Return $MainData
    $first[1] = $second[1]&' '&$second[0]
    Return _ArrayToString($first,',',1)
EndFunc

txt file used for testing

<snip>
Edited by Melba23
Text removed

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 

Share this post


Link to post
Share on other sites

All,

We only have the OP's word that this is in the public domain - I am not happy to leave so many names on the board given the context. Please do not post any more snippets unless you anonymise them. :)

polingkyle,

If you want more help, then please post an anonymised version (e.g. A**** B*****) of the file.

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

arr soory for trouble meliba, i posted with wrong tabs and edited to wrap it correctly, guess 2 late to figure out why your first <snip> happend, tought cos of long list :P

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 

Share this post


Link to post
Share on other sites

bogQ,

No problem. :)

I am just not happy with so much personal information appearing on a public board with only the OP (who we do not know from Adam) telling us it is public knowledge. :huh:

By all means post code and results as long as you do something to disguise the names when you do. :)

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

yeap, i mixed up the order...someone else had something posted to strip out SR, JR, III, etc...you can easily combine that with mine, and it will work just fine.

Also, made my prior post annonymized


IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

jdelaney,

made my prior post annonymized

Thanks. :)

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Here my version:

 

#include <Array.au3>
Global $sText = StringReplace(FileRead(@ScriptDir & "Text.txt"), ", ", "°")
Global $aText = StringSplitW($sText, "°")
Global $i, $x, $y

For $i = 0 To UBound($aText) - 1
    $aText[$i][0] = StringRegExpReplace($aText[$i][0], "(w+)s+(.*)", "$2 $1")
Next

Global $sModified, $sToken
For $y = 1 To UBound($aText) - 1
    For $x = 0 To UBound($aText, 2) - 1
        $sToken = $aText[$y][$x]
        If $sToken Then $sModified &= $sToken & ", "
    Next
    $sModified = StringTrimRight($sModified, 1) & @CRLF
Next

$hFile = FileOpen(@ScriptDir & "Modified.txt", 2)
FileWrite($hFile, $sModified)
FileClose($hFile)


; #FUNCTION# ========================================================================================================================================
; Name .................:   StringSplitW()
; Description ..........:   Splits  a string into columns instead of rows as it is done by SplitString(), like a csv file to a 2d array ;-)
; Syntax ...............:   StringSplitW($sString, $sDelimiter, $iWidthLen)
; Parameters ...........:   $sString - string to split
;                           $sDelimiter - [optional] the delimter how to split the string
;                           $iWidthLen - [optional] length of the row (amount of columns - default is 256)
; Return values .......:    Success - 2d array
;                           Error 1 - either $sString or $delimter is not set
;                           Error 2 - array width exceeded
;                           Error 3 - error splitting string
;
; Version .............:    v0.96 build 2015-01-20 beta
; Author ..............:    UEZ
; Modified ............:
; Remarks .............:    RegEx take from http://stackoverflow.com/questions/4476812/regular-expressions-how-to-replace-a-character-within-quotes
; Related .............:    StringSplit, StringReplace, StringRegExpReplace, StringLen, StringStripCR
; ===================================================================================================================================================
Func StringSplitW($sString, $sDelimiter = ";", $sQuotationMark = '"', $sDummy = "¦", $iWidthLen = 256)
    If $sString = "" Or $sDelimiter = "" Then Return SetError(1, 0, 0)
    Local $chk, $iWidth, $i, $j, $k, $iLen, $iMax = 1, $iMaxWidth
    Local $aPos[1], $l = 0
    Local $aSplit =  StringSplit(StringStripCR($sString), @LF)
    If @error Then Return SetError(3, 0, 0)
    Local $aVertical[$aSplit[0]][$iWidthLen], $iDelimiterLen = StringLen($sDelimiter) - 1, $sLine
    For $k = 1 To $aSplit[0]
        $iLen = StringLen($aSplit[$k])
        If $iLen > 1 Then
            $sLine = StringRegExpReplace($aSplit[$k], '(?m)\' & $sDelimiter & '(?=[^' & $sQuotationMark & ']*' & $sQuotationMark & '(?:[^' & $sQuotationMark & '\r\n]*' & $sQuotationMark & '[^' & $sQuotationMark & ']*' & $sQuotationMark & ')*[^' & $sQuotationMark & '\r\n]*$)', $sDummy)
            $chk = StringReplace($sLine, $sDelimiter, $sDelimiter)
            $iWidth = @extended
            If $iWidth > $iWidthLen Then Return SetError(2, 0, 0)
            If $iWidth >= $iMax Then $iMax = $iWidth + 1
            Switch $iWidth
                Case 0
                    $aVertical[$l][0] = $sLine
                Case Else
                    Dim $aPos[$iWidth * 2 + 2]
                    $j = 1
                    $aPos[0] = 1
                    For $i = 0 To $iWidth - 1
                        $aPos[$j] = StringInStr($sLine, $sDelimiter, 0, $i + 1) - 1
                        $aPos[$j + 1] = $aPos[$j] + 2 + $iDelimiterLen
                        $j += 2
                    Next
                    $aPos[UBound($aPos) - 1] = StringLen($sLine)
                    $j = 0
                    For $i = 0 To UBound($aPos) - 1 Step 2
                        $aVertical[$l][$j] = StringMid(StringReplace($sLine, $sDummy, $sDelimiter), $aPos[$i], $aPos[$i + 1] - $aPos[$i] + 1)
                        $j += 1
                    Next
                EndSwitch
                $l += 1
        EndIf
    Next
    ReDim $aVertical[$l][$iMax]
    Return $aVertical
EndFunc

The content of Text.txt is the text you have provided in your post #3.

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

My last contrib, taking into consideration suffixes:

#include <Array.au3>
Dim $aSuffix[7]=["jr","sr","I","II","III","IV","V"]
$string = "a1 b1 c1 IV, 31, of dison Ave, violation of tpo, continued." & @CRLF & _
"a2 b2 c2 JR, 31, of ison, violation of tpo, continued." & @CRLF & _
"a3 b3, 31, of ison Ave, violation of tpo, continued, pd apptd, no contact." & @CRLF & _
"a4 b4 c5, 40, of an Dr, theft, bench warrant ordered." & @CRLF & _
"a5 b5 c6, 46, of Rd, felonious assault/weapon, dismissed." & @CRLF & _
"a6 b6 c7, 30, of lard Ave, theft, continued, theft, continued." & @CRLF & _
"a7 b7 c8, 22, of 1ard Ave, theft, continued, pd apptd." & @CRLF & _
"a8 b8 c9, 52, of il Hollow Ct, ovi, continued, open container/vehicle, continued, display of license plates, continued."
$atest1 = StringRegExp ( $string, "([ws]+),.*", 3 )
For $i = 0 To UBound ( $atest1 ) - 1
 $atest2 = StringRegExp ( $atest1[$i], "([w]+)s?", 3 )
  $fn = ""
  $ln = ""
  $mi = ""
  $suf = ""
 For $j = 0 To UBound ( $atest2 ) - 1
  Switch $j
   Case 0
    $ln = $atest2[$j]
   Case 1
    $fn = $atest2[$j]
   Case Else
    $bFoundSuffix = False
    For $k = 0 To UBound ( $aSuffix ) - 1
     If $atest2[$j] = $aSuffix[$k] Then
      $suf = $atest2[$j]
      $bFoundSuffix = True
      ExitLoop
     EndIf
    Next
    If Not $bFoundSuffix Then $mi = StringLeft ( $atest2[$j], 1 )
  EndSwitch
 Next
 $mi = StringSTripWS ( $mi, 7 )
 $suf = StringSTripWS ( $suf, 7 )
 If stringlen ( $mi ) > 0 Then
  If stringlen ( $suf ) > 0 Then
   $string_replace = $fn & " " & $mi & " " & $ln & " " & $suf
  Else
   $string_replace = $fn & " " & $mi & " " & $ln
  EndIf
 Else
  If stringlen ( $suf ) > 0 Then
   $string_replace = $fn & " " & $ln & " " & $suf
  Else
   $string_replace = $fn & " " & $ln
  EndIf
 EndIf
 $string = StringReplace ( $string, $atest1[$i], $string_replace )
Next
MsgBox ( 1,1,$string)

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

I apoligize for posting the names. Although, it is public records, I completely understand you needing to protect the community. I will make sure to edit my posts in the future so not to have personal information. Again, I truely appreciate all of the help. I'll let you all know if I end up getting this to work. Thanks!

Kyle

Share this post


Link to post
Share on other sites

In such case, post a pointer where people can freely download the same public data you're working on, from an official website. This way, no name or personal data needs to appear on this forum and we're sure to work on the same problem data as you.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

In such case, post a pointer where people can freely download the same public data you're working on, from an official website. This way, no name or personal data needs to appear on this forum and we're sure to work on the same problem data as you.

Makes sense. Thanks for the tip. (Just to clear the air, the data can be found at http://www.springfieldnewssun.com/news/news/crime-law/municipal-court/nSSdf/)

Kyle

Share this post


Link to post
Share on other sites

Here's something that might get you started in the right direction, it needs work and parsing of the returned array to get what you're looking for, but it should give you some ideas to work with.

#include <array.au3>
$File = FileOpen("parsed.txt")
For $i = 1 To 10
$Text = FileReadLine($File)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Text = ' & $Text & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
$Text1 = StringRegExp($Text, "(\w{1,20})\W(\w{1,20})\W(\w{0,20})\W(\w{0,20})\W(\w{0,20})", 2)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Text1 = ' & $Text1 & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
_ArrayDisplay($Text1)
Next

I've attached the document that I'm parsing, which is a copy and paste of some of the information linked in your post.

parsed.txt


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

As always, all of your suggestions have been much appreciated. I was able to get it to work using my existing code by removing @LF's from the document (thanks kylomas!). So, now my script will fix the first name and I would like to loop it until the document contains no more # signs. Basically, it takes all paragraph breaks and turns them into a # sign. Then I need it to take the first word after the # sign and put it as the last word before the comma (I know that was WAY more confusing than it needed to be). So I took the script that works perfectly and surrounded it with a loop that looks like this:

While 1
$read = FileRead($TextFileName)
If @error = -1 Then ExitLoop
If StringInStr($read, "#") Then
;;
;; SCRIPT FOR FIXING THE NAMES
;;
EndIf
Wend

The problem is that it runs infinitely and never gets out of the loop... :( Any idea what is wrong with my loop? My full script now looks like this:

#include <file.au3>
#Include <string.au3>
#include <array.au3>
Local $username = EnvGet("USERNAME")
Local $userprofile = EnvGet("USERPROFILE")
$TextFileName = $userprofile & "\Desktop\MuniCourt.txt"
WinActivate ("MuniCourt.txt")
Send("^s")
WinClose ("MuniCourt.txt")
;fixes midline returns
$FileContents = FileRead($TextFileName)
$FileContents = StringReplace($FileContents, @CR,"#")
FileDelete($TextFileName)
FileWrite($TextFileName,$FileContents)
$FileContents = 0
$FileContents = FileRead($TextFileName)
$FileContents = StringReplace($FileContents, @CRLF,"#")
FileDelete($TextFileName)
FileWrite($TextFileName,$FileContents)
$FileContents = 0
$FileContents = FileRead($TextFileName)
$FileContents = StringReplace($FileContents, @LF,"")
FileDelete($TextFileName)
FileWrite($TextFileName,$FileContents)
$FileContents = 0

;NameWizard (Changes "Last, First MI" to "First MI Last")
;First person's name is corrected
While 1
$read = FileRead($TextFileName)
If @error = -1 Then ExitLoop
If StringInStr($read, "#") Then
$FileContents = FileRead($TextFileName)
$Name = _StringBetween($FileContents, '#', ',')
If @error Then Exit
$FullName = _StringProper(StringRegExpReplace($Name[0], '#', ''))
$Lastname = _StringBetween($FullName, '', ' ')
$Firstname = _StringBetween($FullName, ' ', '')
$FileContents = FileRead($TextFileName)
$FileContents = StringReplace($FileContents, $Lastname[0] & " " & $Firstname[0], $Firstname[0] & " " & $Lastname[0])
FileDelete($TextFileName)
FileWrite($TextFileName,$FileContents)
$FileContents = 0
$FileContents = FileRead($TextFileName)
$FileContents = StringReplace($FileContents, "#" & $Firstname[0], @CRLF & @CRLF & $Firstname[0])
FileDelete($TextFileName)
FileWrite($TextFileName,$FileContents)
$FileContents = 0
$FileContents = FileRead($TextFileName)
$FileContents = StringReplace($FileContents, ":##", ":",1)
FileDelete($TextFileName)
FileWrite($TextFileName,$FileContents)
$FileContents = 0
stringreplace($Lastname,'##','#',1)
;Reset variables
$Name = 0
$FullName = 0
$Firstname = 0
$Lastname = 0
$FileContents = 0
EndIf
Wend

Share this post


Link to post
Share on other sites

Much closer now! Here's what I've got:

#include 
#Include 
#include 

Local $username = EnvGet("USERNAME")
Local $userprofile = EnvGet("USERPROFILE")
$TextFileName = $userprofile & "DesktopMuniCourt.txt"
WinActivate ("MuniCourt.txt")
Send("^s")
WinClose ("MuniCourt.txt")

;fixes midline returns
$FileContents = FileRead($TextFileName)
$FileContents = StringReplace($FileContents, @CR,"#")
FileDelete($TextFileName)
FileWrite($TextFileName,$FileContents)
$FileContents = 0

$FileContents = FileRead($TextFileName)
$FileContents = StringReplace($FileContents, @CRLF,"#")
FileDelete($TextFileName)
FileWrite($TextFileName,$FileContents)
$FileContents = 0

$FileContents = FileRead($TextFileName)
$FileContents = StringReplace($FileContents, @LF,"")
FileDelete($TextFileName)
FileWrite($TextFileName,$FileContents)
$FileContents = 0

$LineCount = _FileCountLines("MuniCourt.txt")


;NameWizard (Changes "Last, First MI" to "First MI Last")
;First person's name is corrected
Dim $i
Do
$i += 1


$FileContents = FileRead($TextFileName)
$Name = _StringBetween($FileContents, '#', ',')
If @error Then Exit
$FullName = _StringProper(StringRegExpReplace($Name[0], '#', ''))
$Lastname = _StringBetween($FullName, '', ' ')
$Firstname = _StringBetween($FullName, ' ', '')

$FileContents = FileRead($TextFileName)
$FileContents = StringReplace($FileContents, $Lastname[0] & " " & $Firstname[0], $Firstname[0] & " " & $Lastname[0])
FileDelete($TextFileName)
FileWrite($TextFileName,$FileContents)
$FileContents = 0

$FileContents = FileRead($TextFileName)
$FileContents = StringReplace($FileContents, "#" & $Firstname[0], @CRLF & $Firstname[0])
FileDelete($TextFileName)
FileWrite($TextFileName,$FileContents)
$FileContents = 0

$FileContents = FileRead($TextFileName)
$FileContents = StringReplace($FileContents, ":##", ":",1)
FileDelete($TextFileName)
FileWrite($TextFileName,$FileContents)
$FileContents = 0

$FileContents = FileRead($TextFileName)
$FileContents = StringReplace($FileContents, "##", @CRLF)
FileDelete($TextFileName)
FileWrite($TextFileName,$FileContents)
$FileContents = 0

;Reset variables
$Name = 0
$FullName = 0
$Firstname = 0
$Lastname = 0
$FileContents = 0
Until $i = $LineCount

MsgBox (1, "TEST", "This is a test box!")

;Launches the updated file
sleep(1000)
ShellExecute ($userprofile & "DesktopMuniCourt.txt")

The only problem is If $LineCount equals anything higher than 104, the script won't do anything after the loop ends. I told the script to loop once for every line in the document. If the document has 105 or more lines, the loop still works correctly and fixes all names. After the names are fixed, the script stops itself but doesn't do anything that it's supposed to between the end of the loop and the end of the script... Is there some sort of limitation on loops? Thanks.

Kyle

Share this post


Link to post
Share on other sites

Wish I'd saved your original file, as the webpage you referenced has names that are already formatted.

I can say you should look into FileReadToArray().

I will read your file into an array, handling @CRLF, @CR and @LF, and giving you a line count, while reading the file once.

As opposed to reading the file 5 times, writing it 3 times, deleting it 3 times, performing 3 StringReplace() functions on the full file, and then reading the file a fifth time to get the line count.

Edit: Are you saying your file has lines terminated by @CRLF but has @CR characters embedded within the lines?

Edited by Spiff59

Share this post


Link to post
Share on other sites

Another example.

Local $string = "Ali Omar Sheariff, 31, of a fake address, continued." & @CRLF & _
        "de la Harpe Mean Francois, Miscellaneous writer." & @CRLF & _
        "de Looze Henk, 33, a Dutch guy." & @CRLF & _
        "Ballard Liz Anne Marie, 60, of another fake address" & @CRLF & _
        "La Blanc Sean P, 46, homeless." & @CRLF & _
        "Le Barbier Jean Jacques-Francois, 30, 6 ft under." & @CRLF & _
        "van der Zande Jos, 22, no intro needed." & @CRLF & _
        "McMillen Sir Barry E, 52, of another address, continued."

ConsoleWrite(StringRegExpReplace($string, "(?i)(v?a?n? ?d?(?:a|e)?r? ?l?(?:a|e)? ?S+)h(.+?),(.+)", "2 1,3") & @LF)

#cs
    Returns:-
    Omar Sheariff Ali, 31, of a fake address, continued.
    Mean Francois de la Harpe, Miscellaneous writer.
    Henk de Looze, 33, a Dutch guy.
    Liz Anne Marie Ballard, 60, of another fake address
    Sean P La Blanc, 46, homeless.
    Jean Jacques-Francois Le Barbier, 30, 6 ft under.
    Jos van der Zande, 22, no intro needed.
    Sir Barry E McMillen, 52, of another address, continued.
#ce

Share this post


Link to post
Share on other sites

polingkyle,

Thanks for being understanding. :thumbsup:

jchd,

Good idea - I shall remember it for future use. ;)

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...