Link to home
Start Free TrialLog in
Avatar of SirReadAlot
SirReadAlot

asked on

what is the equivalent of StrReverse (which is vb.net) in c#

Hi experts,
I was following this example http://support.microsoft.com/default.aspx?scid=kb;en-us;309013

what is the equivalent of StrReverse (which is vb.net)  in c#

and How do i takecare of it??

thanks
Avatar of DaHa
DaHa

StrReverse is provided as one of the many little helper functions that existed in old school VB and many would want today... unfortunately, there is no official C# alternative.

Luckily though, because of the whole concept of the Base Class Library, you can still use it! In VB.NET when you call StrReverse, it calls the function Microsoft.VisualBasic.Strings.StrReverse(). In order to use it, you would have to set a reference to Microsoft.VisualBasic.dll... however this is generally frowned upon, but still legal and useful.

If you do not want to go this route... you will have to build your own.
Found this on Code Project .  Its a Reverse method that uses recursion.
(Credit goes to mosessaur.)

public static string Reverse(string strValue)
{
    // this is the Termination of the Recursion when the string
        // length is 1 means on char
    if(strValue.Length==1)
    {
        return strValue;
    }
    else
    {
        //print the or store the 1st char every time,
        //so that when 1st Char stored will be the end of the string
        //this way the string will be reversed
        return Reverse( strValue.Substring(1) ) + strValue.Substring(0,1);
    }
}

Paul
ASKER CERTIFIED SOLUTION
Avatar of PaulBarbin
PaulBarbin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SirReadAlot

ASKER

Hi paul, just tried out your code. I
opps!!!          I wonder if u know why this is happening.

error saying
Method 'TestHarness.WebService.Service.GetMessage()' referenced without parentheses
'TestHarness.WebService.Service' does not contain a definition for 'SendMessage'
'TestHarness.WebService.Service' does not contain a definition for 'ReverseMessageFunction'
'TestHarness.WebService.Service' does not contain a definition for 'ReverseMessageSub'


this is the client application code(console). it says

using System;
using System.Web.Services;
using TestHarness.WebService;

namespace TestHarness
{
      /// <summary>
      /// Summary description for Class1.
      /// </summary>
      class Class1
      {
            static void Main(string[] args)
            {
                  string strValue = "This is my message";
                  WebService.Service myService = new WebService.Service();
                  Console.WriteLine(myService.GetMessage);
                  Console.WriteLine(myService.SendMessage(strValue));
                  Console.WriteLine(myService.ReverseMessageFunction(strValue));
                  myService.ReverseMessageSub(strValue);
                  Console.WriteLine(strValue);

            }
      }
}


thanks
i have reduced the error down to

Method 'TestHarness.WebService.Service.GetMessage()' referenced without parentheses
'TestHarness.WebService.Service' does not contain a definition for 'SendMessage'

GetMessage() does exist in the service.asmx class,

can't figure out wat wrong

thanks

it actually worked.

thanks paul