Skip to main content

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

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).


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

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!

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.


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


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!

 

 


Thanks for all your responses!


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.


Reply