The best solution I can think of is to use multiple consecutive retrieves, removing 1 character from the end of $Input_string and using xpath like:
[Code = $Inputsubstring]
until you find a match or you hit some minimum length for $Input_string.
This model share should illustrate the idea:
Instead of looping through the whole list, you could also use a filter or find after retrieving the list. This way you don't have to loop over the list.
How many configurations are you expecting to retrieve from the database? if it aren't that many, I think this isn't a bad solution.
I think you need to swith $input_string and Code. The first argument expects the attribute you want the function to match on and the second part the string value.
So in your case this would result in [starts-wtih(Code, $Input_string). Unless I missed something of course ;)
I don’t have an ideal solution but if it looks like you’re forced to retrieve all configurations and loop through them then you can possibly refine that somewhat by combining it with a fixed substring retrieve also, so you only have to loop through a subset of Configuration objects and not all of them.
So if the minimum length configuration code is three digits then you could take the first three digits of the $inputstring as an $inputsubstring, do an xpath retrieve with starts-with(Code, $inputsubstring) then loop through this subset of Configuration objects to check whether the Input string starts with Iterator/Code.
Might be worth it if you have lots of configuration objects but also in the future you wouldn’t want to introduce a new configuration with length of Code fewer than three digits.