Darkflame808 Posted June 19, 2017 Share Posted June 19, 2017 (edited) I have a situation, I have various strings that look like this... .....................15533.............291928....E .....1....................428............E ...........2999191929281990....................299919192881...................................E etc and so forth. There is a pattern to the madness... It's basically a random amount of "." followed by something not "." followed by a random amount of "." followed by something not "." and so forth. I want to turn all the repetitive ............ into just 1 . So .....................15533.............291928....E becomes .15533.291928.E Solving this riddle will allow me to use a stringtrim with the . as the delimiter and allow me to just extract the 15533 and 291928 from the array. Anyone know how to convert all series of ... into just 1 . ? I can't solve it because the string has two series of .............. in the 1 string. and since the ........... varies, I use that as the delimiter as it will throw off my array value. I hope my question makes sense! Thank you coders for your brain work. I wish I had the ability to solve this, it took me hours of searching other topics just to get this far. Edited June 19, 2017 by Darkflame808 Link to comment Share on other sites More sharing options...
iamtheky Posted June 19, 2017 Share Posted June 19, 2017 $str = ".....................15533.............291928....E" ;~ $str = ".....1....................428............E" ;~ $str = "...........2999191929281990....................299919192881...................................E" msgbox(0, '' , stringregexpreplace($str , "(\.+)" , ".")) ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
Malkey Posted June 19, 2017 Share Posted June 19, 2017 If you are going to use StringSplit() function to split the string on the single dots to get the numbers into an array. It might be easier to by-pass the dots and go straight for the numbers. But be warned, you will be coming face to face with the much maligned Regular Expressions. Although, these two examples are a simple and easy introduction. For more info on Regular Expressions see the StringRegExp function in the AutoIt help file. #include <Array.au3> ; Used only to display array. $str = ".....................15533.............291928....E" ;~ $str = ".....1....................428............E" ;~ $str = "...........2999191929281990....................299919192881...................................E" ;Repeating iamtheky's example MsgBox(0, '', StringRegExpReplace($str, "\.+", ".")) ; Match 1 or more groups of literal dots, "\.+", and replace with 1 dot. ;Or $array = StringRegExp($str, "\d+", 3) ; Match 1 or more groups of digits, "\d+", and return in an array. Parameter "3" - $STR_REGEXPARRAYGLOBALMATCH - Return array of global matches. _ArrayDisplay($array) Link to comment Share on other sites More sharing options...
iamtheky Posted June 19, 2017 Share Posted June 19, 2017 what about this? ;~ $str = ".....................15533.............291928....E" ;~ $str = ".....1....................428............E" $str = "...........2999191929281990....................299919192881...................................E" do $str = stringreplace($str , ".." , "." , 0) until @extended = 0 msgbox(0, '' , $str) ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
Darkflame808 Posted June 19, 2017 Author Share Posted June 19, 2017 Thank you everyone for your assistance! I tried the solutions in order as posted and iamtheky's first post worked a treat! I've spent so much hours rewriting the same script in different ways trying to attack my problem from new angles. Once I applied your fix it was smooth sailing from there. I am very much grateful for your assistance! Link to comment Share on other sites More sharing options...
iamtheky Posted June 19, 2017 Share Posted June 19, 2017 (edited) Thanks, I think this pulls it off on a single line without loops or regex, provided that none of the values are similar, otherwise its going to jack that up. #include<array.au3> $str = ".....................15533.............291928....E" ;~ $str = ".....1....................428............E" ;~ $str = "...........2999191929281990....................299919192881...................................E" msgbox(0, '' , _ArrayToString(_ArrayUnique(stringsplit($str , "." , 2)) , "." , 1)) Edited June 19, 2017 by iamtheky ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
Gianni Posted June 20, 2017 Share Posted June 20, 2017 3 hours ago, iamtheky said: I think this pulls it off on a single line without loops or regex, provided that none of the values are similar, otherwise its going to jack that up. ...just another bizzarre "one line" way #include <array.au3> $str = ".....................15533.............291928....E" ;~ $str = ".....1....................428............E" ;~ $str = "...........2999191929281990....................299919192881...................................E" $aGroups = StringSplit(StringStripWS(StringReplace($str, ".", " "), 7), " ", 2) _ArrayDisplay($aGroups) iamtheky 1 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... 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