473,396 Members | 1,989 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to use Strings Class in C#

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?

Nov 17 '05 #1
4 8861
string newString = MyString.Substring(MyString.Length-2);

"ad" <ad@wfes.tcc.edu.tw> wrote in message
news:eP****************@TK2MSFTNGP10.phx.gbl...
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?

Nov 17 '05 #2
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.)

"ad" <ad@wfes.tcc.edu.tw> wrote in message
news:eP****************@TK2MSFTNGP10.phx.gbl...
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?

Nov 17 '05 #3
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
"ad" <ad@wfes.tcc.edu.tw> wrote in message
news:eP**************@TK2MSFTNGP10.phx.gbl...
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?

Nov 17 '05 #4
Ant
Is this what you want?

string MyString="Test99";

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

Ant
"ad" wrote:
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?

Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

50
by: dataangel | last post by:
I wrote a function to compare whether two strings are "similar" because I'm using python to make a small text adventure engine and I want to it to be responsive to slight mispellings, like...
3
by: Mikael Olofsson | last post by:
Hi! I've asked Google, but have not found any useful information there. Situation: I have a base class, say >>> class base(object): ImportantClassAttribute = None Now, I want to...
2
by: Torben Laursen | last post by:
I handle errors in my code by using my own exception class that takes a number as argument to the constructor, and that number puts a string into the exception class. The user can then catch the...
89
by: scroopy | last post by:
Hi, I've always used std::string but I'm having to use a 3rd party library that returns const char*s. Given: char* pString1 = "Blah "; const char* pString2 = "Blah Blah"; How do I append...
52
by: Paddy | last post by:
I was browsing the Voidspace blog item on "Flattening Lists", and followed up on the use of sum to do the flattening. A solution was: I would not have thought of using sum in this way. When...
23
by: arnuld | last post by:
i was doing exercise 4.3.1 - 4.29 of "C++ Primer 4/e" where authors, with "run-time shown", claim that C++ Library strings are faster than C-style character strings. i wrote the same programme in...
1
by: Edward K Ream | last post by:
Hello all. I'm tracking down memory leaks in my app. To do this I wrote a script to show the numbers of each different type of object. But it doesn't show strings! Here is the script: import...
10
by: =?Utf-8?B?RGFyYSBQ?= | last post by:
Can some one suggest me as why StringBuilder class is better than Strings? -- Never say, Give up
9
by: | last post by:
I am interested in scanning web pages for content of interest, and then auto-classifying that content. I have tables of metadata that I can use for the classification, e.g. : "John P. Jones" "Jane...
5
by: alan | last post by:
Hello world, I'm wondering if it's possible to implement some sort of class/object that can perform mapping from class types to strings? I will know the class type at compile time, like so:...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.