locked
Remove last 4 characters of a filename RRS feed

  • Question

  • fileName = Testing_Workbook.xls
    oWB.SaveAs(saveDest + fileName.Remove(4) + Updated + ".xls");
    The problem with that code is that it is removing the last 4 characters from workbook not the .xls.  What code should I use to remove the .xls extension?
    Monday, February 11, 2013 12:25 AM

Answers

  • I think it'll work

    filename=Testing_Workbook.xls; int len=filename.Length; string newName=filename.substring(0,len-4); oWB.SaveAs(SaveDest+newName+Updated+".xls");



    Regards Kumar Gaurav.

    • Marked as answer by IndigoMontoya Monday, February 11, 2013 12:43 AM
    Monday, February 11, 2013 12:30 AM

All replies

  • I think it'll work

    filename=Testing_Workbook.xls; int len=filename.Length; string newName=filename.substring(0,len-4); oWB.SaveAs(SaveDest+newName+Updated+".xls");



    Regards Kumar Gaurav.

    • Marked as answer by IndigoMontoya Monday, February 11, 2013 12:43 AM
    Monday, February 11, 2013 12:30 AM
  • That got it.  Thank you for the assistance.

    Monday, February 11, 2013 12:38 AM
  • For what it is worth, you might consider next time using Path.GetFileNameWithoutExtension.  That way, you do not need tricky code if you are dealing with .xls, .xlsx, .anyotherthing files.

    --
    Mike
    Monday, February 11, 2013 1:16 AM
  • I will google that.  I have never used that coding before, but as you stated my issue was having to take into account .xls, .xlsx, .xlam etc files.
    Monday, February 11, 2013 2:04 PM