By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,837 Members | 1,766 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,837 IT Pros & Developers. It's quick & easy.

String manipulation question

P: n/a
Hi Everybody,
Can anyone please tell me how I can get the rightmost characters of a string?
In Visual Basic .NET there is still the old-fashioned but handy "right()" function.
Since C# does not support these old stuff, I could not find anything similar.
My guess is that there must be a way to do it by using any method of the String class.

Thanks a lot,
Amintas
Nov 15 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"=?Utf-8?B?QW1pbnRhcw==?=" <am**********@yahoo.com> wrote in
news:F7**********************************@microsof t.com:
Can anyone please tell me how I can get the rightmost characters of a
string? In Visual Basic .NET there is still the old-fashioned but
handy "right()" function. Since C# does not support these old stuff,
I could not find anything similar. My guess is that there must be a
way to do it by using any method of the String class.


Use the length property then copy the characters off the end.
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"
ELKNews - Get your free copy at http://www.atozedsoftware.com

Nov 15 '05 #2

P: n/a
Amintas <am**********@yahoo.com> wrote:
Can anyone please tell me how I can get the rightmost characters
of a string?
In Visual Basic .NET there is still the old-fashioned but handy
"right()" function.
Since C# does not support these old stuff, I could not find
anything similar.
My guess is that there must be a way to do it by using any method
of the String class.


Yup:

string x = "hello".Substring (3); // Gives "lo"

To get the last 5 characters of a string, for instance, you'd use:

string x = myString.Substring (myString.Length-5);

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #3

P: n/a
Hi Chad,
I got it!
Thanks a lot,
Amintas
Nov 15 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.