How to split a string with "\"

Hi team,

I have string A as
“C:\Users\hello\Desktop\AP_\Aug 2022\AP_PDF_Invoices\GD TIP 2345 064522.1.pdf”

I want to extract only “GD TIP 2345 064522.1.pdf”

Please help me with the string manipulation.

Regards,
Gokul

HI @gokul1904

Try this out

Path.GetFileNameWithoutExtension("C:\Users\hello\Desktop\AP_\Aug 2022\AP_PDF_Invoices\GD TIP 2345 064522.1.pdf")
Path.GetFileName("C:\Users\hello\Desktop\AP_\Aug 2022\AP_PDF_Invoices\GD TIP 2345 064522.1.pdf")

Regards
Gokul

1 Like

HI @gokul1904

String manipulation

Split("C:\Users\hello\Desktop\AP_\Aug 2022\AP_PDF_Invoices\GD TIP 2345 064522.1.pdf","\")(7)

Regards
Gokul

1 Like

Hey @gokul1904,

If it’s a file path you can directly use Path.GetFileName(yourPath)
If it’s a simple string then you can use strPNR.Substring(strPNR.LastIndexOf("")+1).ToString

Thanks,
Sanjit

1 Like

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