How to insert characters before .pdf

I have a path string which is like this

Example 1 - C:\Ishan\UiPath Robots\Test\ST36702302070006.pdf

Needed Result is :

C:\Ishan\UiPath Robots\Test\ST36702302070006 - unlocked.pdf

Just an example. there can be anything before .pdf

Example 2 - C:\Ishan\UiPath Robots\Test\ABC.pdf

Needed Result is :

C:\Ishan\UiPath Robots\Test\ABC - unlocked.pdf

Any suggestions ?

1 Like

HI @Ishan_Shelke

Checkout this

"C:\Ishan\UiPath Robots\Test\ABC.pdf".Insert("C:\Ishan\UiPath Robots\Test\ABC.pdf".IndexOf(".pdf")," - unlocked")

Likewise for all the strings

Regards
Sudharsan

assuming your path is in a variable called “testString”

do this:

Path.Combine(Path.GetDirectoryName(testString),Path.GetFileNameWithoutExtension(testString)+"-unlocked" + Path.GetExtension(testString))
@Ishan_Shelke
image

Hi @Ishan_Shelke ,

You can do the following:

  1. You can split the string
  2. get the first item on the array.
  3. Combine the second string and “.pdf”

Example:

strPath = “C:\Ishan\UiPath Robots\Test\ST36702302070006.pdf”
strSecondValue = “- unlocked.pdf”

strPath= strPath.Split(“.pdf”)(0)
NOTE: The value of strPath now will be “C:\Ishan\UiPath Robots\Test\ST36702302070006”

strFinalPath = strPath + strSecondValue
NOTE: strFinalPath value will be “C:\Ishan\UiPath Robots\Test\ST36702302070006 - unlocked.pdf”

I hope this helps. Happy automation!

Kind regards,
Kenneth

Perfect. Thanks @Sudharsan_Ka

1 Like

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