GEOSoft Posted December 10, 2007 Share Posted December 10, 2007 Am I dreaming or is there a way to split a string on more than one delimiter? Of course the option is to run it through a couple of StringReplace() calls. I want to take a string like 149° 23" 54' and split it So I end up with $array[1] = 149, $array[2] = 23 and $array[3] = 11 I thought of just splitting on the spaces but I won't be able to depend on them being there. Someone may enter it as 149°23"54' They way also add N, S, E, W to the end but that will be discarded. BTW: ° is Chr(176) 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...
weaponx Posted December 10, 2007 Share Posted December 10, 2007 (edited) This works but leaves a trailing parentheses on the last element:Works okay now:#include<Array.au3> $String = "149° 23"" 54'" $array = StringSplit(StringTrimRight($String, 1), Chr(176) & '"') _ArrayDisplay($array)oÝ÷ Ù8b³ +Ê^÷¶ºÚ"µÍÚ[ÛYIÐ^K]LÉÝÂÌÍÔÝ[ÈH ][ÝÌMlÉ][ÝÉ][ÝÈ M ÌÎNÉ][ÝÂÔÝSÜXÙË[[ÝHZ[[È[ÙËXÙH[ÛYYÚ]ÚÈÚ]ÛÛ[XËÜ][È^KÙHÚ[YÌÍÜÝ[HÝ[ÔÜ] Ý[ÔYÑ^XÙJÝ[Õ[TYÚ Ý[ÔÝÜÊ ÌÍÔÝ[Ë KJK ][ÝÉÌLÑ ][ÝË ][ÝË ][ÝÊK ][ÝË ][ÝÊBÐ^QÜ^J ÌÍÜÝ[ Edited December 10, 2007 by weaponx Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted December 10, 2007 Moderators Share Posted December 10, 2007 This works but leaves a trailing parentheses on the last element: Works okay now: #include<Array.au3> $String = "149° 23"" 54'" $array = StringSplit(StringTrimRight($String, 1), Chr(176) & '"') _ArrayDisplay($array)oÝ÷ Ù8b³ +Ê^÷¶ºÚ"µÍÚ[ÛYIÐ^K]LÉÝÂÌÍÔÝ[ÈH ][ÝÌMlÉ][ÝÉ][ÝÈ M ÌÎNÉ][ÝÂÔÝSÜXÙË[[ÝHZ[[È[ÙËXÙH[ÛYYÚ]ÚÈÚ]ÛÛ[XËÜ][È^KÙHÚ[YÌÍÜÝ[HÝ[ÔÜ] Ý[ÔYÑ^XÙJÝ[Õ[TYÚ Ý[ÔÝÜÊ ÌÍÔÝ[Ë KJK ][ÝÉÌLÑ ][ÝË ][ÝË ][ÝÊK ][ÝË ][ÝÊBÐ^QÜ^J ÌÍÜÝ[It doesn't use StringSplit() ... but why do we even need it anyway. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
weaponx Posted December 10, 2007 Share Posted December 10, 2007 I just got served. Straight regex was my first idea but I didn't know how to account for the possibility of the spaces not being present. I guess spaces aren't even relevent with this. Link to comment Share on other sites More sharing options...
GEOSoft Posted December 10, 2007 Author Share Posted December 10, 2007 It doesn't use StringSplit() ... but why do we even need it anyway.I need the string split because the 3 resulting numbers get fed to different functions. $Array[1] to Func A() $array[2] and $array[3] To Func B() This is getting very close Actually Using $in = StringStripWS($in, 8) will take care of the white space issue. I can eliminate the ' by using If StringInStr($in, Chr(39)) Then $in = StringReplace($in, Chr(39), "") The whole thing will depend on what the user inputs and that will be determined by the accuracy they need. They might just input the number of degrees or they might add arcminutes and/or arcseconds. So StringRegExpReplace() will probably be the way to go. It's a matter of getting that right. 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...
weaponx Posted December 10, 2007 Share Posted December 10, 2007 The version Sm0ke_N posted worked just fine for me. I tried it with spaces and without. Link to comment Share on other sites More sharing options...
GEOSoft Posted December 10, 2007 Author Share Posted December 10, 2007 The version Sm0ke_N posted worked just fine for me. I tried it with spaces and without.I'm working with it right now.I wrote a Halversine function as part of a UDF but I have to be careful how the data is input. It will only work with degrees so I had to write a second func to convert arcminutes and arcseconds to degrees. If the return of that func is wrong it throws off the whole Halversine function.Thanks to both of you. 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...
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