Funny problem: How fast can you reverse a string in Java and C#?

I saw an interview question.

Write a function to reverse a string.

It’s a simple question, Hmm? But not so simple.

In Java, StringBuilder class provided a convenient method to reverse the characters it holds, and in C#, we have a static method Array.reverse() to help us. Also, we can write it by ourselves(it’s not a big deal, right?).

OK, let’s take a look at how we can do this.

It’s simple. Hmm? We turn the string into char array, and swap the array element. It’s done.

If we use the API provided by .NET Framework, it will be much more simple.

These 2 approaches are all right, and we can reverse an alphabet string and also, we can reverse an Unicode string like “私は中国人です。”. But if we need to reverse 10,000 strings and each string was 10,000 characters long, which one could be faster?

Continue reading

Recommend: Visual Assist X

Since Visual Studio 2008 still does not provide a colorful editor for Visual C++, I decided to find some solution. I’m lucky, I found Visual Assist X very quickly. This is a highly recommended plug-in for C/C++ developers on Windows platform. I even suspicious that Microsoft and Whole Tomato(The company created Visual Assist) had a agreement that Microsoft will not develop any powerful editor for Visual C++ developers. Why? cause you can find out the C# editor is providing some basic functions that Visual C++ editor does not have.

Look at this.

Microsoft Visual Studio Industry Partner

 

Any way, this a great tool, and it is a must-have plug-in for Visual C++. [Get a copy and take a trial] of Visual Assist X and take a look these wonderful features.

Take a tour of Visual Assist X