fix filename when saving gcode

In the proposed filename, the last character was always missing.
Replace some similar string slicing/rfind with splitting.