Skip to main content
Solved

Construct a URL from a Windows file path?

  • April 11, 2023
  • 6 replies
  • 212 views

lacy
Contributor
  • Contributor
  • 3 replies

I'll be the first to admit this may be a dumb newbie question, but I'm struggling!

 

I have an input field that contains a file path like the following:

q:\\staging\\incoming\\1930s\\WI\\Sauk\\1937\\Sauk_WI_WU_11_908_19370707.tif

I need to construct a URL to the file as referenced in a URL, and dump it into another field:

https://server.com/1930s/WI/Sauk/1937/Sauk_WI_WU_11_908_19370707.tif

 

My conceptual approach has been to use string processing to replace q:\\staging\\incoming with https://server.com, and then replace backslashes with forward slashes.

 

Well, you can see where this is going... the slashes and backslashes are wreaking havoc.

 

For example, I've tried various combinations to escape the \\, like:

@ReplaceString(@Value(inputpath),"/\\","/")

... but I either get no results, or a syntax notice.

 

Am I even in the ballpark?? I'd love some suggestions on how to approach this issue.

 

 

Best answer by dustin

Have you tried the StringReplacer?

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

6 replies

dustin
Influencer
Forum|alt.badge.img+31
  • Influencer
  • 627 replies
  • Best Answer
  • April 11, 2023

Have you tried the StringReplacer?


lacy
Contributor
  • Author
  • Contributor
  • 3 replies
  • April 11, 2023

Thanks. I just played with the StringReplacer transformer, and it looks like that will work fine with no fuss. This is where my ignorance/newness of FME shows through. I'm attempting to handle many of my manipulations in the Attribute Manager transformer. That is, I'm still trying to understand when to use a transformer like StringReplacer vs string function like ReplaceString.


dustin
Influencer
Forum|alt.badge.img+31
  • Influencer
  • 627 replies
  • April 12, 2023

Thanks. I just played with the StringReplacer transformer, and it looks like that will work fine with no fuss. This is where my ignorance/newness of FME shows through. I'm attempting to handle many of my manipulations in the Attribute Manager transformer. That is, I'm still trying to understand when to use a transformer like StringReplacer vs string function like ReplaceString.

The ReplaceString function is handy, and I use it all the time actually. But when you have special characters like backslashes, commas or apostrophes to replace, it can get confusing trying to escape these in the syntax. That's when I usually use the StringReplacer.


redgeographics
Celebrity
Forum|alt.badge.img+59
  • Celebrity
  • 3699 replies
  • April 12, 2023

Thanks. I just played with the StringReplacer transformer, and it looks like that will work fine with no fuss. This is where my ignorance/newness of FME shows through. I'm attempting to handle many of my manipulations in the Attribute Manager transformer. That is, I'm still trying to understand when to use a transformer like StringReplacer vs string function like ReplaceString.

In more general terms, while you can do a lot of stuff using functions in the AttributeManager I find it's often easier to manage if you use separate transformers for it. In this particular case the StringReplacer is definitely easier to set up. Just 2 of them would do the trick, no need to use Regular Expressions or anything.


lacy
Contributor
  • Author
  • Contributor
  • 3 replies
  • April 12, 2023

Thanks for the tips, much appreciated!


ebygomm
Influencer
Forum|alt.badge.img+44
  • Influencer
  • 3422 replies
  • April 12, 2023

No need to quote or escape backslashes

@ReplaceString(@Value(inputpath),\,/)

image