Kappa Posted December 30, 2012 Posted December 30, 2012 Hey,I have a problem to pick the strings in a file. I know that you have to use StringRegExp, but I can not figure out how. Here's an example: DOC;NO;BIGAs you can see, the constant is a string followed by two dots. Do you have any advice, please?Kappa.
Moderators Melba23 Posted December 30, 2012 Moderators Posted December 30, 2012 Kappa,Welcome to the AutoIt forum. What exactly are you trying to extract from the "DOC;NO;BIG" strain? If it is "NO" then the _StringBetween function should be able to help you. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Kappa Posted December 30, 2012 Author Posted December 30, 2012 Thanks for the welcome. I would like to extract "DOC", "NO" and "BIG". So any string before and after the colon.
Moderators Melba23 Posted December 30, 2012 Moderators Posted December 30, 2012 Kappa,If the delimiter is always ";" then you can do that very easily with StringSplit: #include <Array.au3> $sString = "DOC;NO;BIG" $aSplit = StringSplit($sString, ";") _ArrayDisplay($aSplit)M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Kappa Posted December 30, 2012 Author Posted December 30, 2012 Thanks, but, not knowing how many strings are there before and after the colon, I can not use that command for the way I want (or at least I think). That was an example, if you want I can find myself in this situation:DOC;NOorDOC;NO;BIG;LOGorDOCThe most that I could do is this:#include <Array.au3> $String = "DOC;NO;BIG" $Split = StringSplit($String, ";") For $Element In $Split MsgBox(0, "", "Result is: " & @CRLF & $Element) NextBut there are two problems:1. also takes $Split[0]2. does not include the last case (only a word without anything else)
Developers Jos Posted December 30, 2012 Developers Posted December 30, 2012 Not sure what you mean with item 2 but this shows the entries: $String = "DOC;NO;BIG" $Split = StringSplit($String, ";") For $x = 1 to UBound($Split)-1 ConsoleWrite($Split[$x] & @crlf) ;### Debug Console Next Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
Kappa Posted December 30, 2012 Author Posted December 30, 2012 Thanks Jos. Adapting your example I solved it. Thanks also to Melba23!
UEZ Posted December 30, 2012 Posted December 30, 2012 Try this: #include <Array.au3> $sText = "DOC;NO;BIG;LOG" $aResult = StringSplitter($sText) _ArrayDisplay($aResult) $sText = "DOC" $aResult = StringSplitter($sText) _ArrayDisplay($aResult) $sText = "DOC;NO;" $aResult = StringSplitter($sText) _ArrayDisplay($aResult) Func StringSplitter($sString, $sDelimiter = ";", $bRemoveLastDelim = True) If $sString = "" Then Return 0 If $bRemoveLastDelim And StringRight($sString, 1) = $sDelimiter Then $sString = StringTrimRight($sString, 1) Local $aTokens = StringSplit($sString, $sDelimiter, 2) If Not @error Then Return $aTokens Local $aToken[1] $aToken[0] = $sString Return $aToken EndFunc Br, 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
PhoenixXL Posted December 31, 2012 Posted December 31, 2012 I know that you have to use StringRegExp,Indeed a Simple Example ; Splits through a SEMI-COLON (;) #include <Array.au3> $sInput = 'DOC;NO;BIG;' $sOutput_Array = StringRegExp($sInput, '([^;]+)', 3) _ArrayDisplay( $sOutput_Array ) My code: PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners. MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.
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