How to use Strings Class in C#

  • Thread starter Thread starter ad
  • Start date Start date
A

ad

I want to use

string MyString="Test99";
Strings.Rigt(MyString,2);

to get the "22" from my string.

But I can't do that with CSharp.

Strings is belong to Microsoft.VisualBasic Namespace.

How can I use it with CSharp?
 
Wouldn't that be "99", not "22"?

Anyway, try using this instead (which works in both C# and VB.NET):

string MyString="Test99";
string partialString = MyString.Substring(MyString.Length - 2);

(You will need to make sure that MyString has at least two characters, or
this will throw an exception.)
 
Here's how:

Add to your C# project a reference to the "Microsoft VisualBasic .Net
Runtime" assembly,
add this statement to the top of your code:
using Microsoft.VisualBasic;
and then just it like you would any other assembly.

as in Debug.WriteLine(Strings.Right("Test99", 2);

This dirty little secret is probably being used by more than one ex-VB
programmer who prefers to keep using the good old well-known VB6 runtime
routines instead of learning the .Net class library. Personally, I don't
recommend it; you'd be better off knuckling down and learning the class
library, but as a shortcut it's probably OK. I'll never tell.

HTH,
Tom Dacon
Dacon Software Consulting
 
Is this what you want?

string MyString="Test99";

string strOP = MyString.Substring(4,2);

Ant
 
Back
Top