I'm having trouble limiting the number of letters I wasn't appearing. I'm trying to get just the last two but that has been a difficulty. This is what I did;
if (year.length() > 2) {
year = year.substr(0, 2);
}
For example, if you have the year 2016, just 16 is selected.
CodePudding user response:
subString
first parameter is the starting position and second is the number of strings from that position, so first, we take out the length of the string subtract -2 from it.
the second parameter is 2 because we need two characters.
eg : 2016 , first parameter is year subString(4-2,2);
year.substr(year.length() - 2,2)