c# - How to Remove number from Extension with string? -


i want remove number extension string in c#.

for example : "url1234.pdf" want last answer looks "url.pdf"

thank contribution

  var filename = "";             if (file != null && file.contentlength > 0)             {                 filename = system.io.path.getfilenamewithoutextension(file.filename); //path.getfilename(file.filename);                 var extension = system.io.path.getextension(file.filename);                 dbconnect.opendb();                 dbconnect.dbselect("select max(id) id tblfileupload");                 if(dbconnect.dr.read())                 {                     filename += dbconnect.dr["id"].tostring();                 }                 dbconnect.closedb();                 var path = path.combine(server.mappath("~/file/"), filename+extension);                 new fileuploadlayer().save("aa", filename, file.contentlength);                 file.saveas(path);                 uploadfile("aa");             } 

i save file extension(.pdf). file name has numbers also.(url1234.pdf).so, when call need remove numbers , need string part (url.pdf).

you can use regex shown or simple linq query, i'd recommend system.io.path:

string originalpath = "url1234.pdf"; string dir = path.getdirectoryname(originalpath);              // in case "" string extension = path.getextension(originalpath);            // .pdf string fn = path.getfilenamewithoutextension(originalpath);    // url1234 string newfn = string.concat(fn.where(c => !char.isdigit(c))); // url string newpath = path.combine(dir, newfn + extension);         // url.pdf 

Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -