Solved

Get length of a string in NWC Workflow

  • 20 October 2022
  • 8 replies
  • 222 views

Userlevel 1
Badge +4

Hello,

 

How can I get the length of a string in NWC Workflow. I see there is a Length function in NWC Forms, but I am looking for this in NWC Workflows. 

 

Thank you.

icon

Best answer by SimonMuntz 21 October 2022, 00:57

View original

8 replies

Userlevel 4
Badge +10

May or may not work depending on the string your starting with.


 



 

Userlevel 1
Badge +4

Thank you @bsikes !!


 


That is rather counter intuitive, but it worked! 

Userlevel 6
Badge +22

Hi,


 


My approach would be to use a Regular expression to split the string up into a collection.
The config would look like this:


Then use a Count Items in collection action to count how many letters there are in the collection.


For some reason the count is always one more than required so just use a calculate a value action to subtract one.
 


Workflow would look like:


Export Key valid until this time on the 24th of October:
ma8vjTraMZYyHn6CzTfFM3tZmXRbDYTKWG5sGGUwxgjkkxap2

Userlevel 1
Badge +4

Thank you for this alternative solution, @SimonMuntz .


 


I tested your example and it works great for a single word. The string we want to check the length of could be any number of words, spaces and punctuation. What regex would you recommend for that situation? 

Userlevel 6
Badge +22
Hi,

I think this regex would cover it.
[Ss]
Userlevel 1
Badge +4

Thank you @SimonMuntz 


 


The regex [Ss] did indeed work with multiple words. And it even worked when I included a trailing space. 


 


I think this solution is cleaner than one I previously marked as the answer.

Userlevel 4
Badge +10

My only concern with @SimonMuntz suggestion, and this may be unfounded, was if there was a max limit on a collections size. I have no idea if there is one - but if there is, that may be a limitation you run into with that solution. 

Userlevel 6
Badge +22

Hi,


 


Collection do have a limit of 5000 objects.


So as long as the string is under 5k characters (which is a lot) my solution will work.

Reply