what you've mentioned is essentially what needs to be done. however, since the mode string could contain any of the modes in $chanmodes, that's why you need to factor it in to the script to check which are expected to take a parameter and which arent
and yes, you need to loop through all characters in $1 to achieve this, that's not unreasonable. as i said theres several snippets on mircscripts.org that do the work for you, i'll try to find a specific url if anyones interested