SKris Posted April 1, 2011 Share Posted April 1, 2011 i have text file with some coordinates like this: 123,434 453,975 827,832 ... i want to make a script to copy those coords in another file like this: $A[1]="123" $A[2]="453" $A[3]="827" ..... and $B[1]="434" $B[2]="975" $B[3]="832" ... Can u help me out? thankyou Link to comment Share on other sites More sharing options...
r3dbull Posted April 1, 2011 Share Posted April 1, 2011 (edited) I start off by admitting that I am not an expert, but I would go trough these steps: 1) StringSplit all the strings in the first text file with "," as string delimiter 2) Assign the [1] value to array named $A[$i] 3) Assign the [2] value to array named $B[$i] Example: $File = FileOpen("file1.txt", 0) If $File = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf While 1 $Line = FileReadLine($File) If @error = -1 Then ExitLoop $array=StringSplit($line, ",") ;->>That would result in having an array like this for the first two values ;array[0] => 2 ;array[1] => 123 ;array[2] => 434 $A[$i]=$array[1] $B[$i]=$array[2] $i=$i+1 WEnd This sould work, for what you asked. Notice that I haven't tested this, so double check the code I wrote, I might have wrote down something wrong ~ Cheers, r3dbull. Edited April 1, 2011 by r3dbull Link to comment Share on other sites More sharing options...
Mat Posted April 1, 2011 Share Posted April 1, 2011 (edited) You are talking about a normal CSV file, if you search the forum for that then you'll see that this is a pretty common problem.If you think it through then it is simple:Read the file (FileRead)Split it into lines (StringSplit with @CRLF and option 1)Size the arrays! Resizing is a slow process, and you know the length in advance so use it. (Redim)Using the next line, split it into its ',' parts (StringSplit with ',')Add the parts into the arrays (The array has already been sized in part 3 so its just a simple assignment.Go back to part 4 until you've done all the linesWhere needed I've added function names and other info. It should be easy to do with the helpfile.The only thing which won't make sense unless you've programmed for a while is why you need to use option 1 in stringSplit with @CRLF. The reason is that @CRLF = @CR & @LF, so is not one character. You StringSplit(string, Chr1 & Chr2) splits on Chr1 OR Chr2, so you will get blank entries in the array.MatEdit: The above example is missing WEnd at the end of the loop, and the While $i<100 can just be While 1 as the loop will exit when there are no more lines to read (The IF test after FileReadLine does that for you). Edited April 1, 2011 by Mat AutoIt Project Listing Link to comment Share on other sites More sharing options...
guinness Posted April 1, 2011 Share Posted April 1, 2011 Your avatar looks familiar? You're not Hannes123 are you? UDF List:  _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
r3dbull Posted April 1, 2011 Share Posted April 1, 2011 (edited) Thanks Mat for your reply, I adjusted the above code for Skris if he would like to test it. Edited April 1, 2011 by r3dbull Link to comment Share on other sites More sharing options...
saywell Posted April 1, 2011 Share Posted April 1, 2011 If the paired data have a continuing relationship with one another, it might be more sensible to use a 2-d array so that array[1][1] = 123 array[1][2] = 434 array[2][1] = 453 array[2][1] = 975 etc just to keep them together and make it easier to use later in your script. William Link to comment Share on other sites More sharing options...
Malkey Posted April 1, 2011 Share Posted April 1, 2011 Try this.#include <Array.au3> Local $sStr = "123,434" & @CRLF & _ "453,975" & @CRLF & _ "827,832" ;or ;Local $sStr = FileRead("FilePath\Name.txt") Local $A = StringRegExp($sStr, "(\d+),", 3) Local $B = StringRegExp($sStr, ",(\d+)", 3) _ArrayDisplay($A, "Array $A") _ArrayDisplay($B, "Array $B") Link to comment Share on other sites More sharing options...
SKris Posted April 1, 2011 Author Share Posted April 1, 2011 thankyou so much guys i used Malkey method and it works perfect. ty Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now