Skip to main content
Solved

Issue with FindString() to match "101" in "101,102"

  • June 30, 2023
  • 4 replies
  • 53 views

mzuer
Contributor
Forum|alt.badge.img+5

Dear All,

 

Here is my issue with the FindString() function :

 

I have the following string stored in user parameter value_to_test = "101,102" ; the attribute "ProgNum" contains values that range from 100-900 and I want to set a new attribute "FoundNum" to be = "true" when "ProgNum" is one the (comma-separated) values of value_to_test.

 

As FindString(string,strToFind) should return the index in string that matches strToFind , I've tried the following expression :

@FindString($(value_to_test),@Value(ProgNum))

I have also tried the FindStringRegularExpression

@FindRegularExpression($(value_to_test),@Value(ProgNum))

None of the them is working ! Quite despaired I've also tried to revert $(value_to_test) and @Value(ProgNum) in the function call, but it does not work better...

 

Does anyone have an explanation what it is not working and what I am doing wrong ??

 

Thanks in advance

 

NB : I know that I could work with AttributeSplitter etc. but I would like to know why the FindString and FindRegularExpression functions are not working here

Best answer by geomancer

The problem is that value_to_test contains comma's. When you replace these with spaces, @FindString works as expected.

If you want to work with comma's in value_to_test, you can use a Conditional Value in the AttributeManager.

Conditional_Value_3Alternatively, you can use a StringSearcher.

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.

4 replies

david_r
Celebrity
  • June 30, 2023

Try inserting a ParameterFetcher to get $(value_to_test) into an attribute and use that in FindString() rather than the parameter reference.


geomancer
Evangelist
Forum|alt.badge.img+60
  • Evangelist
  • Best Answer
  • June 30, 2023

The problem is that value_to_test contains comma's. When you replace these with spaces, @FindString works as expected.

If you want to work with comma's in value_to_test, you can use a Conditional Value in the AttributeManager.

Conditional_Value_3Alternatively, you can use a StringSearcher.


david_r
Celebrity
  • June 30, 2023

The problem is that value_to_test contains comma's. When you replace these with spaces, @FindString works as expected.

If you want to work with comma's in value_to_test, you can use a Conditional Value in the AttributeManager.

Conditional_Value_3Alternatively, you can use a StringSearcher.

Good catch @geomancer​ , I didn't see that at first. It's then possible to enclose the reference with double quotes, e.g.

@FindString("$(value_to_test)","@Value(ProgNum)")

Unless value_to_test or ProgNum contains double quotes, of course...


mzuer
Contributor
Forum|alt.badge.img+5
  • Author
  • Contributor
  • June 30, 2023

The problem is that value_to_test contains comma's. When you replace these with spaces, @FindString works as expected.

If you want to work with comma's in value_to_test, you can use a Conditional Value in the AttributeManager.

Conditional_Value_3Alternatively, you can use a StringSearcher.

thanks a lot @geomancer and @david_r !

Definitely, I'll never get used to FME's weird under-the-hood behavior and its implicit and unexpected feature type handling/conversion...