string ConvertCodes( string binary )
{
// what to return
string retval = "";
// what to restore the passed in value to just incase
string tempCopy = binary;
foreach( PairItem i in CodeList )
{
// if the CODE (i.e. "011") is a prefix of the passed in string
if( binary.StartsWith( i.CODE ) )
{
// add the symbol (i.e. "i") to the return value string
retval+=i.Symbol.ToString();
// update the passed in string for further checking
binary = binary.SubString( i.CODE.Length );
// check the update string, if it equals "", there were no further matches
if( ConvertCodes(binary) == "" )
{
// reset the return value
retval = "";
// restore the passed in string
binary = tempCopy;
}
}
}
return retval
}
I ran through this code in debug mode for a simple string, and it found the correct return value, but it still returned "".