I was hoping someone could guide me to the best solution to a problem I am having. I need to write some code that will return a specific string based on another string. Essentially if the string I have is "X" then I need a way of identifying "X" and returning "Y".
The strings won't actually be "X" or "Y", that's just an example. Currently I am using a case statement but it feels messy. Is this a good job for a hash map? I will give some pseudo code below on what I am currently doing:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
string x = "";
function whatIsString(theString)
{
switch(string)
{
case"A":
x = "xyz"breakcase"B":
x = "zyx"breakdefault:
x = theString
}
return x;
}
So.. in short, is there a better (or more common) way of doing what I did above? The other option I can think of would be to just do a series of if statements but I figured a switch statement would be better than that... perhaps that is an incorrect assumption.