Skip to main content
Nintex Community Menu Bar
Solved

Removing last two characters from string


Forum|alt.badge.img+3

Hello, I have a variable in my workflow whose length is not consistent. I want to run an action in the workflow to remove the last two characters (always the last 2). I believe regular expression is the way to do this, but I do not know how to format the action. Thanks!

Best answer by Garrett

AutomationPerso wrote:

Interesting. Why does “count collection” count the number of characters? Shouldn’t it return a value of 1 since there is only one value in the collection?

It extract each character and insert into a collection. “apple” → [“a”, “p”, “p”, “l”, “e”]
Once the length is known, its easy to extract from a string eg 1st three chars, last three chars etc

 

Also, I think a simpler way to do this (thanks to your help) would be apply a regex and split using the expression .{2}$

With regex, there is many ways to manipulate strings. 

 

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

3 replies

Garrett
Forum|alt.badge.img+16
  • Scout
  • 904 replies
  • July 22, 2023

Hi @AutomationPerso 

  1. Count the string length → int_textlength
  2. Calc int_textlength_minus2 = int_textlength - 2
  3. Use the Modify String action to Extract substring  

 Export Key: PCHLvfgoVViDnC5FnkcnwFNrnpha9cjULXS8zYXYnoWqRXs5L

Translate

Forum|alt.badge.img+3

Interesting. Why does “count collection” count the number of characters? Shouldn’t it return a value of 1 since there is only one value in the collection?

Also, I think a simpler way to do this (thanks to your help) would be apply a regex and split using the expression .{2}$

Translate

Garrett
Forum|alt.badge.img+16
  • Scout
  • 904 replies
  • Answer
  • July 22, 2023
AutomationPerso wrote:

Interesting. Why does “count collection” count the number of characters? Shouldn’t it return a value of 1 since there is only one value in the collection?

It extract each character and insert into a collection. “apple” → [“a”, “p”, “p”, “l”, “e”]
Once the length is known, its easy to extract from a string eg 1st three chars, last three chars etc

 

Also, I think a simpler way to do this (thanks to your help) would be apply a regex and split using the expression .{2}$

With regex, there is many ways to manipulate strings. 

 

Translate

Reply


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