Fetch Name from URL

Certified Senior Developer

Hi,

I have an URL of the format : https://www.google.com/<unique_id>_<fileName>_<remaining url>

Now my requirement is I want to fetch the filename out of the URL ... the first part will always remain the same  i.e.

first is https ... till .com/

then comes an unique identifier 

then followed by '_'

then followed by filename

then followed by '_' and the remaining URL 

Can anyone help me fetch the filename ? 

  Discussion posts and replies are publicly visible

Parents Reply
  • Ok, so we can say the first part of the URL will always be 60 characters long (the length of the initial part of the URL plus the 36 characters of the unique Id).

    So we can extract the url after all of this "prefix". That will leave us with the filename and the trailing part of the URL. We also know that the filename is terminated by the "?" character so we can split the remaining string at this point:

    a!localVariables(
      local!fileNameStartsAtPosition: 60, /* in reality you'd make this a constant */
      local!fileNameAndRemainingUrl: fn!right(
        ri!url,
        fn!len(ri!url) - local!fileNameStartsAtPosition
      ),
      fn!split(local!fileNameAndRemainingUrl, "?")[1]
    )

Children