>>>' Reverse the input string, without using the StrRever function in the VB6 >>>' compatibility assembly >>>Function ReverseString(String source) As String >>> Dim chars() As Char = source.ToCharArray() >>> Array.Reverse(chars) >>> Return New String(chars) >>>End Function >>>>>>Unfortunately it is VB.NET not C#. Main goal here is to convert whole string to array and then Reverse the array and return converted array back to string :-) I hope NET gurus will give you more beautiful solution.
>>using System; >> >>class sample >>{ >> static void Main() >> { >> Console.WriteLine("Write text to reverse and press [enter]"); >> string inputStr = Console.ReadLine(); >> Console.WriteLine( ReverseString( inputStr ) ); >> } >> >> public static string ReverseString(string source) >> { >> char[] aStr = source.ToCharArray(); >> Array.Reverse(aStr); >> return new String( aStr ); >> } >>} >>If you have .net 2.0 SDK, go to command prompt, write this with notepad to a .cs file, compile using "csc.exe".
// crt_strrev.c // This program checks a string to see // whether it is a palindrome: that is, whether // it reads the same forward and backward. // #include <string.h> #include <stdio.h> int main( void ) { char* string = "Able was I ere I saw Elba"; int result; // Reverse string and compare (ignore case): result = _stricmp( string, _strrev( _strdup( string ) ) ); if( result == 0 ) printf( "The string \"%s\" is a palindrome\n", string ); else printf( "The string \"%s\" is not a palindrome\n", string ); }Cetin