Skip to main content
Nintex Community Menu Bar
Solved

Removing last two characters from string

  • July 22, 2023
  • 3 replies
  • 566 views

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

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. 

 

3 replies

Garrett
Forum|alt.badge.img+16
  • Scout
  • 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


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}$


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

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.