Fix bad porting of C# Substring and bad porting of switch statement