Returns a new String that begins with the character at the specified zero-based startIndex and extends to the character at endIndex - 1
In your case, you are populating account's contact name with very first string from contactNames and trimming the last character from returned string.
For example
String str = 'SLA-UPsdfdsfdsfG-4HR-4ON';
String res = str.substring(0, str.length()-1);
system.debug('Your String---'+res);
You will get the result like this SLA-UPsdfdsfdsfG-4HR-4O
In your case, you are populating account's contact name with very first string from contactNames and trimming the last character from returned string.
For example