Skip to main content
Question

Count the number of characters and numbers in a given string


salvaleonrp
Enthusiast
Forum|alt.badge.img+15

Given this string:

2. ALL FPL LIGHTS TO BE 100W HPS UNLESS OTHERWISE NOTED.

I'd like to produce two attributes that will give me the count of characters and numbers on this given string:

In Microsoft Word its called Word Count statistics, except that Word does not specify numeric or string, just the count of strings (with or without spaces).

Count of Numbers

Count of Strings including special characters and spaces4

52

8 replies

Forum|alt.badge.img+7

Hi @salvaleonrp

I took a quick look at your question and managed to get the desired result using two stringsearchers returning a list with matches. Counting the number of elements in the list allows you to get the correct count. Of course you can adapt the regex for the characters to also take into account the spaces / special characters (e.g. \\S|\\s).


david_r
Celebrity
  • March 1, 2017
Do you need the numbers (2, 100) or the digits (2, 1, 0, 0)? And should the character count include the numbers/digits?

salvaleonrp
Enthusiast
Forum|alt.badge.img+15
  • Author
  • Enthusiast
  • March 1, 2017
jeroenstiers wrote:

Hi @salvaleonrp

I took a quick look at your question and managed to get the desired result using two stringsearchers returning a list with matches. Counting the number of elements in the list allows you to get the correct count. Of course you can adapt the regex for the characters to also take into account the spaces / special characters (e.g. \\S|\\s).

@jeroenstiers this may work for me. Thanks!

erik_jan
Contributor
Forum|alt.badge.img+17
  • Contributor
  • March 1, 2017

I would do a StringLengthCalculator to calculate the total length, The use the StringReplacer to replace all numeric values (regex \\d) and repeat the StringLengthCalculator. So numeric is total minus end value.


ebygomm
Influencer
Forum|alt.badge.img+32
  • Influencer
  • March 1, 2017

You can do this in an attribute creator, counting the length after replacing all the numbers with nothing and separately counting the length after replacing all non-digits with nothing

Gives the ouput


salvaleonrp
Enthusiast
Forum|alt.badge.img+15
  • Author
  • Enthusiast
  • March 1, 2017
ebygomm wrote:

You can do this in an attribute creator, counting the length after replacing all the numbers with nothing and separately counting the length after replacing all non-digits with nothing

Gives the ouput

Work for me as well!

 

 


salvaleonrp
Enthusiast
Forum|alt.badge.img+15
  • Author
  • Enthusiast
  • March 1, 2017

Thanks for all your responses!


gio
Contributor
Forum|alt.badge.img+15
  • Contributor
  • March 2, 2017

or sort( i.e. puts numbers in front of characters)

then

-use regexp lookahead (?=\\w) or (?=\\d) or (?=special characters in character class) in indexmode....gives u the start index.

-split string by highest or lowest number, special character, and or character.

-turn ascii and use codes..and split by numbers.

..etc.


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