Background: I was invited to an interview with a high profile company, and I was asked the following question before I was told that I had not been interviewed for this post (C #, mvc3, razor). I am sincerely interested in how to solve this problem.
Question: "Write a method that takes a char array, trims whitespace, and returns the same array." After some thought, I was told to replace the space with "\ o".
I started with:
public static char[] Trim(char[] c) { for (int i = 0; i < c.Length; i++) { if (c[i] == '\r' || c[i] == '\n' || c[i] == '\t') { c[i] = '\o'; } } }
I was told that I should use the same array, I can not put it in a list and call ToArray() . However, I think that if the array remains the same size, it cannot be "trimmed".
source share