SeF Posted October 18, 2010 Share Posted October 18, 2010 Hello!I'm still trying to understand how to use StringSplit properly with delimiters (from StringRegExp HelpFile).Like, I want to split this single text:"47.42-3-00 - Comércio varejista de material elétrico 47.53-9-00 - Comércio varejista especializado de eletrodomésticos e equipamentos de áudio e vídeo 47.54-7-01 - Comércio varejista de móveis"Into this:$Variable[1] = "47.42-3-00 - Comércio varejista de material elétrico "$Variable[2] = "47.53-9-00 - Comércio varejista especializado de eletrodomésticos e equipamentos de áudio e vídeo"$Variable[3] = "47.54-7-01 - Comércio varejista de móveis"I'm trying to first split by using the numbers, like:'number' & 'number' & '.' & 'number' & 'number' & '-' & 'number' & '-' & 'number' & 'number'But, don't know how to do it.Any ideas?I won't post any script because still don't have any. I'm still testing some methods.. Tks! Link to comment Share on other sites More sharing options...
nitekram Posted October 18, 2010 Share Posted October 18, 2010 does it always start with 47? 2¢ All by me:"Sometimes you have to go back to where you started, to get to where you want to go." "Everybody catches up with everyone, eventually" "As you teach others, you are really teaching yourself." From my dad "Do not worry about yesterday, as the only thing that you can control is tomorrow." WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2 AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit Docs SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language Programming Tips Excel Changes ControlHover.UDF GDI_Plus Draw_On_Screen GDI Basics GDI_More_Basics GDI Rotate GDI Graph GDI CheckExistingItems GDI Trajectory Replace $ghGDIPDll with $__g_hGDIPDll DLL 101? Array via Object GDI Swimlane GDI Plus French 101 Site GDI Examples UEZ GDI Basic Clock GDI Detection Ternary operator Link to comment Share on other sites More sharing options...
Bowmore Posted October 18, 2010 Share Posted October 18, 2010 This should give you the result you require. #include <array.au3> $sData = "47.42-3-00 - Comércio varejista de material elétrico 47.53-9-00 - Comércio varejista especializado de eletrodomésticos e equipamentos de áudio e vídeo 47.54-7-01 - Comércio varejista de móveis" $sTemp = StringRegExpReplace($sData," ([0-9]{2}\.)",@CRLF & "$1") $aRows = StringSplit($sTemp,@CRLF,3) ;Just to show result _ArrayDisplay($aRows, "Data Split into separate Rows") "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook Link to comment Share on other sites More sharing options...
Ascend4nt Posted October 18, 2010 Share Posted October 18, 2010 Here's one way without StringSplit (assuming the given pattern is consistent throughout): #include <Array.au3> $sStr="47.42-3-00 - Comércio varejista de material elétrico 47.53-9-00 - Comércio varejista especializado de eletrodomésticos e equipamentos de áudio e vídeo 47.54-7-01 - Comércio varejista de móveis" $aArr=StringRegExp($sStr,'([\d.-]+\D+(?=\s\d|$))',3) _ArrayDisplay($aArr) My contributions: Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs | Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) | Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code) Link to comment Share on other sites More sharing options...
SeF Posted October 19, 2010 Author Share Posted October 19, 2010 does it always start with 47? No. Sometimes starts with 00, 01, 21 etc. This should give you the result you require. #include <array.au3> $sData = "47.42-3-00 - Comércio varejista de material elétrico 47.53-9-00 - Comércio varejista especializado de eletrodomésticos e equipamentos de áudio e vídeo 47.54-7-01 - Comércio varejista de móveis" $sTemp = StringRegExpReplace($sData," ([0-9]{2}\.)",@CRLF & "$1") $aRows = StringSplit($sTemp,@CRLF,3) ;Just to show result _ArrayDisplay($aRows, "Data Split into separate Rows") Thanks! It worked pretty well! Here's one way without StringSplit (assuming the given pattern is consistent throughout): #include <Array.au3> $sStr="47.42-3-00 - Comércio varejista de material elétrico 47.53-9-00 - Comércio varejista especializado de eletrodomésticos e equipamentos de áudio e vídeo 47.54-7-01 - Comércio varejista de móveis" $aArr=StringRegExp($sStr,'([\d.-]+\D+(?=\s\d|$))',3) _ArrayDisplay($aArr) Thanks! Also worked pretty well! --- Thanks everyone! Link to comment Share on other sites More sharing options...
GEOSoft Posted October 19, 2010 Share Posted October 19, 2010 "Pretty well" suggests that it didn't work quite as you needed. If you can point out what didn't behave properly, it may be an easy fix to the expression. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
SeF Posted October 19, 2010 Author Share Posted October 19, 2010 (edited) "Pretty well" suggests that it didn't work quite as you needed. If you can point out what didn't behave properly, it may be an easy fix to the expression. Sorry. I didn't used the right word. Actually, it worked perfectly! I used Bowmore's script. Here is the final script: #include<Excel.au3> $oExcel = _ExcelBookAttach("Pessoa Fisica.xlsb", "filename") $i = 2 Do $Celula = _ExcelReadCell($oExcel, "E" & $i) If $Celula <> "Não informada" Then $sTemp = StringRegExpReplace($Celula, " ([0-9]{2}\.)", @CRLF & "$1") $aRows = StringSplit($sTemp, @CRLF, 1) If $aRows[0] <> "1" Then $p = 1 $c = 0 Do $oExcel.Application.Range(Chr(Asc("E") + $c) & $i).Select ;Just to watch the script "doing your job". For fun ;D _ExcelWriteCell($oExcel, $aRows[$p], Chr(Asc("E") + $c) & $i) $c = $c + 1 $p = $p + 1 Until $c = $aRows[0] EndIf EndIf $i = $i + 1 Until $i = _ExcelReadCell($oExcel, "E" & $i) = "" ; Just changed one parameter from StringSplit because I needed to know how many arrays was splited. It was about 160,000 Excel's Rows in less than 1 hour. I'm satisfied with the code! Anyway, thanks for the concern! Edited October 19, 2010 by SeF 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