Skip to main content
Solved

Count number of unique characters into a string

  • February 12, 2016
  • 4 replies
  • 232 views

philippeb
Enthusiast
Forum|alt.badge.img+22

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!

Best answer by takashi

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

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

4 replies

davideagle
Contributor
Forum|alt.badge.img+22
  • Contributor
  • February 12, 2016

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


takashi
Celebrity
  • Best Answer
  • February 13, 2016

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


takashi
Celebrity
  • February 13, 2016

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),[^-]+,"")) 

philippeb
Enthusiast
Forum|alt.badge.img+22
  • Author
  • Enthusiast
  • February 15, 2016

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.