I am trying to remove the last character from a string variable in MSFlow. I've tried several things but so far no luck. Any feedback on the best way to do this?
I am trying to remove the last character from a string variable in MSFlow. I've tried several things but so far no luck. Any feedback on the best way to do this?
This is helpful but make sure you check if your variable has data before using the function.
Example of the error you will receive:
InvalidTemplate. Unable to process template language expressions in action 'Compose' inputs at line '1' and column '2727': 'The template language function 'take' parameters are out of range: 'count' must be a positive integer. The provided valus is '-1'. Please see https://aka.ms/logicexpressions#take for usage details.'.
Hi @bclarkuncc ,
The methods provided by Scott are valid, and you could also consider using take() function.
take(variables('String'),sub(length(variables('String')),1))
Image reference:
There are a lot of functions in WDL function that can be used to process strings. For more details, please refer to Online doc:
https://docs.microsoft.com/en-us/azure/logic-apps/workflow-definition-language-functions-reference
Best Regards,
This should help....
In my example, I have a string called varString.
The expression that I used to get all but the last character is:
substring(variables('varString'),0,add(length (variables('varString')),-1))
The substring function allows me to extract part of a string - I specify where to start (position 0) and how many characters I want.
To find how many characters to take, I use the length expression to give me the string length and subtract one for the result.
There are a few ways to do this, but nearly all of them revolve around utilizing the Compose action. See the Functions documentation for Flow, and the Using Functions within Flow using the Compose Action blog post for some further ideas on how it can be used.
If you could provide an expanded screenshot of your Flow and steps, and of any detailed error messages you're receiving we could likely better assist you.
If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!
WarrenBelz
146,700
Most Valuable Professional
RandyHayes
76,287
Super User 2024 Season 1
Pstork1
66,015
Most Valuable Professional