How to check if my string ends with ".pdf"

Hey guys ,

A string manipulation favour here -

I have my string like -
C:\Users\ggeshtwin\Desktop\AP_All_Latest_Run\FIN B2 03.31.2022.pdf

How do I check if my string ends with “.pdf” so that I can pick that.

I know there is a way like String.contains(“.pdf”)

But wanted to know if there is anything related to the end point of a string to distinguish with?

Regards,
Gokul

YourStringVar.ToUpper.EndsWith(“.PDF”)

2 Likes

Hi @gokul1904

How about this express?

Directory.GetFiles(Environment.CurrentDirectory+"\Input\","*.pdf").Tostring

This expression will get only the PDF file inside the folder. Just give the Path

Regards
Gokul

1 Like

Hello @gokul1904 ,

You can use : YourStringVar.Split("."c).LastOrDefault.equals(“pdf”)

Regards,
Rohith

1 Like

Thanks everyone!

As an alternate also have a look at:

1 Like

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