Dryden Posted August 12, 2012 Posted August 12, 2012 (edited) Hi,So I'm trying to find a given text in a .txt file that has 200 to 500 lines and the text that I want is allways between # 010 # and # 101 #For example:Lorem ipsum dolor sit amet, consectetur adipisicing elit,sed do eiusmod tempor incididunt ut labore et doloremagna aliqua. Ut enim ad minim veniam, quis nostrudexercitation ullamco laboris nisi ut aliquip ex ea commodo# 010 #consequat. Duis aute irure dolor in reprehenderitin voluptate velit esse cillum dolore eu fugiat nulla# 101 #pariatur. Excepteur sint occaecat cupidatat non proident,sunt in culpa qui officia deserunt mollit anim id est laborumWhat I want is to put the text in bold in a variable.Any help woul be appreciated.thx in advance Edited August 12, 2012 by Dryden "Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life." - Terry Pratchett.
Thamiel Posted August 12, 2012 Posted August 12, 2012 (edited) I couldn't find the post that I first found the following snippet wrote by someone else and I take no credit for it, but it works great for what your after To use it $str = "# 010 #Your String of course# 101 #", $start = '# 010 #', $end = '# 101 #' ; A Modified String < Between > Search ------------------------------------------------------ Global $pos Func stringbetween($str, $start, $end) $pos = StringInStr($str, $start) If Not @error Then $str = StringTrimLeft($str, $pos + StringLen($start) - 1) $pos = StringInStr($str, $end) If Not @error Then $str = StringTrimRight($str, StringLen($str) - $pos + 1) Return $str EndIf EndIf EndFunc ;==>stringbetween Edited August 12, 2012 by Thamiel
Deltron0 Posted August 12, 2012 Posted August 12, 2012 (edited) $source = "magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo# 010 #consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla# 101 # pariatur. Excepteur sint occaecat cupidatat non proident," $StartMarkerText = "# 010 #" $EndMarkerText = "# 101 #" $start = StringInStr($source,$StartMarkerText) + StringLen($StartMarkerText) $end = StringInStr($source,$EndMarkerText) $length = $end - $start $newvalue = StringMid($source,$start,$length) ConsoleWrite($newvalue) Edit: I posted this before seeing the post above - that function is probably a better route, especially if you need to do that task with a lot of different starting and ending markers. Edited August 12, 2012 by Deltron0
UEZ Posted August 12, 2012 Posted August 12, 2012 Try this: $sText = _ "Lorem ipsum dolor sit amet, consectetur adipisicing elit," & @CRLF & _ "sed do eiusmod tempor incididunt ut labore et dolore" & @CRLF & _ "magna aliqua. Ut enim ad minim veniam, quis nostrud" & @CRLF & _ "exercitation ullamco laboris nisi ut aliquip ex ea commodo" & @CRLF & _ "# 010 #consequat. Duis aute irure dolor in reprehenderit" & @CRLF & _ "in voluptate velit esse cillum dolore eu fugiat nulla# 101 #" & @CRLF & _ "pariatur. Excepteur sint occaecat cupidatat non proident," & @CRLF & _ "sunt in culpa qui officia deserunt mollit anim id est laborum" $sCaptured = StringRegExpReplace($sText, "(?s)(.*#s*d+s*#)(.*)(#s*d+s*#.*)", "$2") MsgBox(0, "Test", $sCaptured) 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
Moderators Melba23 Posted August 12, 2012 Moderators Posted August 12, 2012 (edited) Dryden, And another: $sSource = "magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip " & _ "ex ea commodo# 010 #consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse " & _ "cillum dolore eu fugiat nulla# 101 # pariatur. Excepteur sint occaecat cupidatat non proident," $sExtract = StringRegExpReplace($sSource, ".*010s#(.*)#s101.*", "$1") ConsoleWrite($sExtract & @CRLF) M23 Edited August 12, 2012 by Melba23 Forum stripped backslashes 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
Dryden Posted August 12, 2012 Author Posted August 12, 2012 Gr8. Thx guys! "Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life." - Terry Pratchett.
somdcomputerguy Posted August 12, 2012 Posted August 12, 2012 And last (for now) and probably not least - the _StringBetween function! - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change.
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