How to count the number of specific characters in a field value?

Al_22614
Al_22614 Altair Community Member
edited August 2023 in Community Q&A

I am trying to count the number of specific characters in a field value.  For example, how to calculate to number of commas (",") in the string value, below:

"aaaa, bbbb, cccc"

The formula should result in the number 2.

Thanks for your help

Al

Answers

  • Nicholas_21406
    Nicholas_21406
    Altair Employee
    edited August 2023

    Hi Al,

    I would suggest you create a new column, with all of the commas replaced with the empty string, and then create another column that subtracts the length of your new column from the length of your original column.

    Does that make sense?

  • Lasse
    Lasse Altair Community Member
    edited August 2023

    Hi,

    One option is also to replace all characters except commas and then calculate the length, like:

    Len(RegexReplace(original_field;"[^,]";""))

    -Lasse

  • Al_22614
    Al_22614 Altair Community Member
    edited August 2023

    Thanks for quick reply... Calculating the length difference after Replace ing "," with "", got my expected results... Many Thanks