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 11:24:13
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
09/10/2006 11:14:45
Irv Adams
MSC Managed Care, Inc.
Florida, United States
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01160535
Message ID:
01160568
Views:
12
>>>>( 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
>
>Cetin,
>
>Thanks. I really need to learn more C#, haven't dabbled in C since late-Eighties. Would you know how to write this in straight C? I'm not certain if her class actually uses C# or just C.
>
>Thanks,
>
>Irv.
public string ReverseString( char* source )
{
  char reversed[] = source;
  for(int i=0;i<strlength(source);i++);
  {
    *(reversed--) = *(source++);
  }
  return reversed;
}
PS: Untested. But should be like this as I remember core C.
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
Reply
Map
View

Click here to load this message in the networking platform