Solved

Count number of unique characters into a string

  • 12 February 2016
  • 4 replies
  • 39 views

Badge +8

Hi,

I have this string for example : "Hello-World! Let's talk-about-you!"

If I want to know the number of "-" (here would be 3) into that string, how could I do that with a transformer?

Thanks!

icon

Best answer by takashi 13 February 2016, 07:25

View original

4 replies

Badge +14

I'm sure there are a few options, but I would use a StringSearcher and put the matches into a list, then expose the list and count the elements. Like this:

countstringinstances.fmw

Userlevel 2
Badge +17

Also FME String Functions might be an option in this case.

Userlevel 2
Badge +17

Also FME String Functions might be an option in this case.

0684Q00000ArLIzQAN.png

A more direct expression flashed. Remove every character except hyphens, and then get the length.

@StringLength(@ReplaceRegEx(@Value(str),[^-]+,"")) 
Badge +8

A more direct expression flashed. Remove every character except hyphens, and then get the length.

@StringLength(@ReplaceRegEx(@Value(str),[^-]+,"")) 

OK great this is exactly what I need.

Reply