Skip to Content

Count the occurrences of a character in a string


The following information will step you through counting the occurrances of a specified character in a String container.

  1. Create a subquery with the following as a new column:

    Length(<ColumnName>) - Length(Replace(<ColumnName>, '<char>', ''))
  2. Input the column you want to count into <ColumnName> and input the single character you want to count as <char>. The first part of the expression is counting the length of <ColumnName> and the second part is replacing the given character with an empty string and counting the whole string. The whole expression subtracts the length of the original string from the string without the inputted characters and returns a count of the number of given chracters in the original string.

    Use Case: You may want to count the number of commas in a list (like a Tags Control) and +1 to get the number of items:

    Length(T.ProductList) - Length(Replace(T.ProductList, ',', ''))


The above example assumes there are no commas in the actual text contained in the String.