Change file extension in a variable

hi team

I have a variable that has the following value
D:\Data Extraction from Excel for Indorama\Data\Input\ds-500-1ait0228 - spécification technique d’instrument, 1-ait-0228 - 1.0.0.xls
i want to change it to
D:\Data Extraction from Excel for Indorama\Data\Input\ds-500-1ait0228 - spécification technique d’instrument, 1-ait-0228 - 1.0.0.pdf

the file name can change into anything
and xls can also be xlsx
so how should I change it

Hi,

Can you try the following expression?

System.IO.Path.Combine(System.IO.Path.GetDirectoryName(yourFileName),System.IO.Path.GetFileNameWithoutExtension(yourFileName)+".pdf")

or

System.Text.RegularExpressions.Regex.Replace(yourFilename,"\.[^.]+$",".pdf")

Regards,

It worked thankyou :slight_smile:

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.