Get last two characters of a string

  • Thread starter Thread starter RP
  • Start date Start date
R

RP

I store current year in string format. I want to get the last two
values of the year. For example: if year is 2007, I want 07.

Which string function to use ?
 
I store current year in string format. I want to get the last two
values of the year. For example: if year is 2007, I want 07.

Which string function to use ?

Use Substring and the Length property:

string lastTwoChars = original.Substring (original.Length-2);

Jon
 
Use Substring and the Length property:

string lastTwoChars = original.Substring (original.Length-2);

Jon

In this case, it may be important to mention that you can do:
date.ToString("yy");

to get directly the wanted result.

Kind regards.
Anthony
 
BlueTrin said:
In this case, it may be important to mention that you can do:
date.ToString("yy");

to get directly the wanted result.

Only if the value is a DateTime, while the OP indicated he was storing
the Year as a string.

Chris.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top