6 answers
here are some extra steps that may help
Pardon all the debugs , but if you post it to an Execute Anonymous window you will see exactly what is happening.RegardsAndrewString id= 'KC-012345';
System.debug('===raw=='+id);
Integer index = id.lastIndexOf('-');
String text = id.substring(index+1);
System.debug('===text=='+ text);
Integer textToNumber= Integer.valueOf(text);
System.debug('===text to number==='+ textToNumber);
textToNumber++;
System.debug('===new text to number==='+ textToNumber);
String numberToText = String.ValueOf(textToNumber);
System.debug('---padded number ---' + numberToText.leftPad(6,'0'));
String newEmp = 'KC-'+ numberToText.leftPad(6,'0');
System.debug('new ID '+ newEmp);