Vinayaka N Vinayaka N - 6 months ago 37
C# Question

How to display second text from right side using substring in c#

I am trying display text from right side. For Example 57001 to 58000 Lbs (D) In that text I need to display only 'D' I have tried using substring my code is below

mystring = mystring.Substring(mystring.Length - 2);

for the above code answer is 'D)' but I need to display only 'D' Please help me.


You will need to specify 2 parameters when calling the method Substring.

1 - where does it starts.

2 - how long should it be.


mystring.Substring(startIndex, substringLength);

In your case :

mystring.Substring(mystring.Length - 2, 1);

If you don't specify its length it will take by default the whole string coming right next to your startIndex (included).