Ok, this is a bit of as strange query. I am filtering a dataset of various foods that have been eaten at various times of the day. I end up with a list of strings in the form of "Morning-Vegetables", "Afternoon-Vegetables", "Evening-Vegetables" etc.. A formula I am using needs to trim the time of day before the foodtype, so I have 3 formulas which use the functions TrimLeft(String, "Morning-"), TrimLeft(String, "Afternoon-"), TrimLeft(String, "Evening-").
Everything works fine for various types of food and various times of day. Except for "Evening-Egg". I have attached a small sample showing what happens. I have changed "Egg" to "Eggs" to illustrate the point a bit more clearly.
If I do Trimleft(String, "Afternoon-") on "Afternoon-Eggs" = "Eggs"
If I do Trimleft(String, "Evening-") on "Evening-Eggs" = "s" ?????
If I do Trimleft(String, "Evening") on "Evening-Eggs" = "-Eggs"
I am using Alteryx 10.06.28907.
Like I said, TrimLeft works fine with Coffee, Beer, Fish, Meat, I just seems to have a problem with "Egg" preceded by the word "Evening-".
I know this seems like the request of a crazy person, but is anyone else getting this? The last value of the second column of the attached reads "s" for me, whereas I am expecting "Eggs".
If I am doing something really silly, then sorry!
Pete
Solved! Go to Solution.
The Trim functions, take in two arguments, the string to trim, and a list of character to replace. The Trim functions do not work like a Replace function (where the sequence of characters is respected), the list of characters can be in any order, and they will be trimmed.
for example,
TrimLeft([Names],"Evening")
is the exact same thing as
TrimLeft([Names],"gnievE")
Another function to consider is Regex_Replace, then in the pattern, we can specify that the sequence of character to replace have to be at the beginning of the string (with the ^ character), and this will work similar to the replace function.
For example:
Regex_Replace([Names],"^Evening-","")
and
Regex_Replace([Names],"^Afternoon-","")
I think are closer to what you are looking for.
Another tool to consider is Text-to-Columns, to split the string on the dash "-" character.
Take a look at the attached workflow with these additions.
Many Thanks Joe!
I hadn't realized that Trim worked in that way. Regex_Replace does seem to be the way forward.
Thanks for helping me with this!
Pete
User | Count |
---|---|
18 | |
17 | |
14 | |
6 | |
5 |