Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
(Fox/C# folks?) A simple loop in C#
Message
From
09/10/2006 10:52:05
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01160535
Message ID:
01160553
Views:
14
>>( I posted this in the .NET forum also, just fishing for Fox/C# crossover folks here)
>>
>>I have a simple programming assignment I'm trying to help my daughter with, but I'm a helpless FoxPro addict and I'm not sure how to do this in C.
>>
>>She needs to write a loop to parse a string backwards, so 'Hello World' becomes 'dlroW olleH' and so on. Very simple, I could do it in Fox, but I don't know much about C.
>>
>>Thanks,
>
>Here one solution I found at: http://www.devx.com/vb2themax/Tip/19500?type=kbArticle&trk=MSCP
>
>' 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.

Nice Boris:)
Irv,
Translation to C#:
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".
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform