JennMaughan Posted February 4, 2018 Share Posted February 4, 2018 I'm bridging into a new area of experience in Autoit, and not sure what is the best to use. ------------------------------------------------------------------ I have written a portion of AutoIt script that reads through a notepad file and copies the data between an identified starting phrase and ending phrase, then saves the result in specific Excel cells. What I need to have happen is to then to go back ... and extract the number that is listed in each string. There will only be one number such as.... 75,689. I'm not sure how to do that the easiest ------------------------------- Overall... looking at the project globally... All I really need to do is extract the number following a certain phrase in a file ....and Just because I didn't know how to do it better... I'm running the $aExtract = _StringBetween($sText, $sStart, $sEnd)... pasting string into Excel... then hoping to just extract the number from that string... I'm using Notepad just because it seemed easy If there's a much better way overall... please lol, let me know .. Thx Thanks! Jen Link to comment Share on other sites More sharing options...
mikell Posted February 4, 2018 Share Posted February 4, 2018 Regular expressions do exactly this Example : $str = "What I need to have happen is to then to go back ... and extract the number 75,689 that is listed in each string." $nbr = StringRegExp($str, '\d+(?:,\d+)?', 1) If IsArray($nbr) Then Msgbox(0,"", $nbr[0]) This code can be adapted so you might provide sample strings badcoder123 and Danyfirex 2 Link to comment Share on other sites More sharing options...
iamtheky Posted February 4, 2018 Share Posted February 4, 2018 there are soooo many ways to do this. Understanding why mikell is right is a greater goal than just using his correct solutions. #include<array.au3> $str = "What I need to have happen is to then to go back ... and extract the number 75,689 that is listed in each string." msgbox(0, '' , StringStripWS(_ArrayToString(stringsplit($str , "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ." , 2), ""), 3)) Danyfirex, badcoder123, czardas and 1 other 4 ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
mikell Posted February 4, 2018 Share Posted February 4, 2018 55 minutes ago, iamtheky said: Understanding why mikell is right is a greater goal than just using his correct solutions. Hmm... does this mean that I should have provided some relevant comments to explain the code ? if so you're not wrong Let's wait first for the OP's feedback, to be sure that it works for all the possibly concerned strings and fits all the requirements (including the hidden ones) etc Link to comment Share on other sites More sharing options...
iamtheky Posted February 4, 2018 Share Posted February 4, 2018 Not necessarily, I think uncommented code forces you to learn just as much as commented code may teach. ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
kylomas Posted February 5, 2018 Share Posted February 5, 2018 @iamthekey - As Goldberg'ish as that is I would never have thought of using stringsplit like that. Bravo! iamtheky 1 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 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