Friday, May 2, 2014

A Better Solution To My charToString Method?

It is always a good idea to get data out of code, so make a dictionary of translations. The simplest code I can think of is



static var translations = new Dictionary<char, char> {
{ '/', '\\'},
{ ' ', '_'}
};

public static string TranslateReader(int count, BinaryReader reader)
{
return new String(reader.ReadChars(count)
.Select(c => translations.ContainsKey(c) ?
translations[c] : c)
.ToArray());
}



My 2c, it is a very rude thing to state that you assume all the people in the world are about to be rude to you. Can you keep your low opinion of people who give up their time to help others to yourself?




Paul Linton


No comments:

Post a Comment