the123punch Posted July 24, 2007 Posted July 24, 2007 Hello Guys, I know this might be an easy one, I am trying to find a string function that will return me an array with all the positions of spaces in that string. I know such functions exist in scripting languages like PHP or perl but I cannot seem to find it in Autoit. If anyone could send me on a lead it would be appreciated. Thank you.
xcal Posted July 24, 2007 Posted July 24, 2007 (edited) There's probably a better, "proper" way, but this works. ; _GetCharPos(string, character) ; Returns an array of positions ; $array[0] = total returns #include <array.au3> ; just for _ArrayDisplay() $somevar = _GetCharPos('this is some string with a bunch of spaces', ' ') _ArrayDisplay($somevar) Func _GetCharPos($string, $search) Local $array[1], $i = 1, $ret While 1 $ret = StringInStr($string, $search, 0, $i) If $ret = 0 Then ExitLoop ReDim $array[UBound($array) + 1] $array[$i] = $ret $i += 1 WEnd $array[0] = UBound($array) - 1 Return $array EndFunc edit - Made it return an array and be more UDF-ish for finding diff character types, just add in your own error checking. Edited July 24, 2007 by xcal How To Ask Questions The Smart Way
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