Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
(Fox/C# folks?) A simple loop in C#
Message
De
09/10/2006 11:58:17
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
09/10/2006 11:14:45
Irv Adams
MSC Managed Care, Inc.
Floride, États-Unis
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01160535
Message ID:
01160576
Vues:
22
>>>>( 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.

From C++ help:
// 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
Ç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
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform