Multiple choice technology web technology

How do I get the rightmost part of a string?

  1. str.Substring(str.Length);

  2. str.Substring(str.Length - 1);

  3. str.LastChar();

  4. str.RightChar();

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

To get the rightmost character of a string, you use Substring(str.Length - 1, 1) or Substring(str.Length - 1). This starts from the last character position. Option A with str.Length would cause an ArgumentOutOfRangeException, and options C and D are not valid string methods.