String manipulation question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
=?Utf-8?B?QW1pbnRhcw==?= said:
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
 
Amintas said:
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);
 
Back
Top