GetSubstringOccurrenceCount
Counts the number of times a character or substring occurs within the text.
Syntax
bool GetSubstringOccurrenceCount (string TextToSearch , string Substring , string StorageVariable , string CaseSensitive)
Parameters
- TextToSearch
- Type: String
- Substring
- Type: String
- StorageVariable
- Type: String
- CaseSensitive
- Type: String
Smart parameters are supported for all parameters.
Returns
False if an error occurs. Otherwise, True.
Level
Any level.
Details
The action counts the number of times the substring is found within the TextToSearch. The substring can be a single character or a string of characters. Typically, the TextToSearch is a smart parameter that references a variable or field.
The substring count is stored in the specified StorageVariable location. Subsequent actions can access the variable and use it as required.
The StorageVariable smart parameter can reference a variable or the text value of an existing field. If StorageVariable specifies a DCO variable that does not exist, it is created . If the target specified by StorageVariable already contains a value when this action is called, it is overwritten by the new value.
Example 1
GetSubstringOccurrenceCount("This is the test string", "t", "@X.Count", "")
The example counts the number of lowercase "t" characters in the string and stores the value in a variable called "Count" on the current object.
Example 2
GetSubstringOccurrenceCount("AAAaA aaAAAA", "aa", "@P\Field1", "False")
This example performs a case-insensitive comparison looking for the word "aa" in "AAAAa aaAAAA". The count is stored in a field that is attached to the current page called "Field1". The total count is 5 because overlaps are not counted. The matches are "AA", "Aa", "aa", "AA" and "AA".
Example 3
GetSubstringOccurrenceCount("@P\Field1", "Total", "@P\Field1.MyCount", "False")
rrCompareNumeric("@P\Field1.MyCount",">", "10")
The action searches the text value in the child field object called "Field1". It performs a case-insensitive count for the word "Total" in the field. The count total is stored in a variable called "MyCount" on "Field1". Then rrCompareNumeric checks the value of the count. If the occurrences are more than 10, then the action will return True and the next action in the function will run. If the value is 10 or less, then rrCompareNumeric will return False and skip to the next function in the rule.
See also
rrCompareNumeric in the RuleRunnerLogic action library.
Refer to the top level help for more information regarding smart parameters and the RuleRunnerLogic action library top level help for the complete smart parameter reference.