Skip to main content
Solved

issue searching string


robinso1
Contributor
Forum|alt.badge.img+2

I am trying to use the string search command to extract the file names from a text string, Path attribute. by reverse searching the path string in order to establish the location of the last sub directory i.e. \\

@FindString(@Value(Path),\\,-0,caseSensitive=TRUE)

 

The forward search works but I can't get the reverse (right to left) to work! using a negative startIdx

 

image 

Best answer by nielsgerrits

Please also check the FileNamePartExtractor.

View original
Did this help you find an answer to your question?

9 replies

nielsgerrits
VIP
Forum|alt.badge.img+54
  • Best Answer
  • July 28, 2023

Please also check the FileNamePartExtractor.


ebygomm
Influencer
Forum|alt.badge.img+39
  • Influencer
  • July 28, 2023

A negative start index doesn't mean it searches from right to left, rather that it returns the position of the first match from the end of the string rather than the start.

 


robinso1
Contributor
Forum|alt.badge.img+2
  • Author
  • Contributor
  • July 28, 2023
ebygomm wrote:

A negative start index doesn't mean it searches from right to left, rather that it returns the position of the first match from the end of the string rather than the start.

 

ok, but Isn't that effectively the same thing if im attempting to establish where the file name starts


ebygomm
Influencer
Forum|alt.badge.img+39
  • Influencer
  • July 28, 2023
robinso1 wrote:

ok, but Isn't that effectively the same thing if im attempting to establish where the file name starts

Sorry, poor wording on my part.

 

Example:

Search the word pagan for letter a

imageIf start index is 0 or not set, this would return the a in position 1

If start index is set to -1 the search starts at position 4 and so the result is -1 (a is not found)

If start index is set to -2, the search starts at position 3, a is found and so the result is 3

If start index is set to -4, the search starts at position 1, a is found and sot he result is 1

 

The negative start index just sets the start of the search from the end of the string, the search itself is still left to right


robinso1
Contributor
Forum|alt.badge.img+2
  • Author
  • Contributor
  • August 1, 2023
robinso1 wrote:

ok, but Isn't that effectively the same thing if im attempting to establish where the file name starts

Thanks for this, will try and find another way


ebygomm
Influencer
Forum|alt.badge.img+39
  • Influencer
  • August 1, 2023
robinso1 wrote:

ok, but Isn't that effectively the same thing if im attempting to establish where the file name starts

What are you trying to get? The filename, the last subdirectory or something else?

 

The FilenamePartExtractor will give both the above

_filename - filename with extension

_rootname - filename without extension

_dirname - last subdirectory


robinso1
Contributor
Forum|alt.badge.img+2
  • Author
  • Contributor
  • August 1, 2023
robinso1 wrote:

ok, but Isn't that effectively the same thing if im attempting to establish where the file name starts

The Path attribute was created from a dir listing exported to csv and not via FME, unfortunately. effectively just a string from which i'm attempting to extract the file name. if that makes sense?


ebygomm
Influencer
Forum|alt.badge.img+39
  • Influencer
  • August 1, 2023
robinso1 wrote:

ok, but Isn't that effectively the same thing if im attempting to establish where the file name starts

The FilenamePartExtractor works on an attribute, so that's not an issue at all. Set the attribute containing your string as the Source Filenameimage 


robinso1
Contributor
Forum|alt.badge.img+2
  • Author
  • Contributor
  • August 2, 2023
robinso1 wrote:

ok, but Isn't that effectively the same thing if im attempting to establish where the file name starts

Thank you, that worked a treat


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings