Search a DC attribute string value
-
If you wanted to see if the string "Hello" was in the following attribute string value...
qwertyHello12345
How would you do it?
The trick is, can you return one value (like "TRUE" or "1") if found and another (like "FALSE" or "0") if not?
I would be interested in a Ruby solution too if necessary!
-
Add the required text to the end of the string then use "find", then compare the length of the original string and position returned by find. By adding your text to the end, find will always return a value
-
Thanks pcmoor.
So... trying to understand this. You have:
=if((find("hello",Astring&"hello",1)-len(Astring))<0,"true","false")
where Astrin is set to
hellggggheloxxhell
So in other words
=if((find("hello","hellggggheloxxhell"&"hello",1)-len("hellggggheloxxhell"))<0,"true","false")
Which I think means:
If FIND returns a number that is greater than the length of the search string, return true.So you are sort of forcing FIND to return something if the search string is not found by a certain position by adding the search string onto the end of the search haysatck,right?
I'm not sure I understand completely but this seems like some ninja stuff!
-
More or less correct. As you know find returns a position but that is -1 (an error) if there is no instance of the required text. So adding the text you are trying to find to the end of the original string, then if there is no other instance, then position return will not be -1 but the length of the original string plus one,
So the difference between (position-len(original string)) returns a negative number if another instance is found, which if<0 will return trueadded the above example with extra attributes to show steps clearer. but better to use one liners to save space in your DC dialog, once understood
-
YES! I see now. That is some pretty sweet re-engineering of the pretty remedial string functions! I do wish FIND would just return FALSE if the string is not found but oh well. Thanks Again pcmoor!
Advertisement