ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage functions / Standard functions / String functions
  • Search in an array: managing ambiguities
  • StringCount and UNICODE
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Others
Stored procedures
Calculates:
  • the number of occurrences of a specific character string (by respecting the search criteria) in another character string.
  • the number of occurrences of a set of strings in an array.
Example
Res = StringCount("anastasia", "a")         // Returns 4
Res = StringCount("toto titi tito", "to")   // Returns 3
Res = StringCount("toaster", "X")       // Returns 0
Res = StringCount("An Indian hunts an eagle", "an") // returns 2
Res = StringCount("An Indian hunts an eagle", "an", WholeWord) // returns 1
Res = StringCount("An Indian hunts an eagle", "an", IgnoreCase) // Returns 3
Res = StringCount("An Indian hunts an eagle", "an", IgnoreCase + WholeWord) // Returns 2
Res = StringCount("anastasia", ["a","s"])         // Returns 6
Syntax

Number of occurrences of a character string Hide the details

<Result> = StringCount(<Initial string> , <Search string> [, <Options>])
<Result>: Integer
  • Number of occurrences,
  • 0 if no occurrence exists or if <Search string> corresponds to an empty string ("").
<Initial string>: Character string
Text in which the occurrences of <Search string> must be found.
<Search string>: Character string
Text to find in <Initial string>.
<Options>: Optional constant (or combination of constants)
Search options:
IgnoreCaseSearches ignoring the case (uppercase/lowercase characters).
WholeWordSearches for a whole word, i.e, between spaces or punctuation characters (characters other than a letter or a digit).
WEBDEV - Browser code This constant is not available.

Number of occurrences of strings in an array Hide the details

<Result> = StringCount(<Initial string> , <Array of search strings> [, <Options>])
<Result>: Integer
  • Number of occurrences,
  • 0 if there are no occurrences or if <Array of search strings> contains empty strings ("").
<Initial string>: Character string
Text in which the occurrences of <Search string> must be found.
<Array of search strings>: Array
Name of the array that contains the strings to be found in the <Initial string>.
<Options>: Optional constant (or combination of constants)
Search options:
IgnoreCaseSearches ignoring the case (uppercase/lowercase characters).
WholeWordSearches for a whole word, i.e, between spaces or punctuation characters (characters other than a letter or a digit).
WEBDEV - Browser code This constant is not available.
Remarks

Search in an array: managing ambiguities

When the search strings are substrings of other strings in the array, the longest strings are taken into account.
Example: If the ["after", "afternoon", "afterward"] array of strings must be found in "Come this afternoon after the game", the first occurrence found will be "afternoon" (and not "after").

StringCount and UNICODE

You have the ability to use ANSI strings, Unicode strings and buffers in the different parameters of the function.
The following conversion rule is used for the Ansi systems (Windows or Linux):
  • If at least one of the strings is a buffer, all the strings are converted to buffers and the operation is performed with buffers.
  • If the first condition is not met and there is at least one Unicode string, all the strings are converted to Unicode and the operation is performed in Unicode (the conversion is performed with the current character set, if necessary).
  • Otherwise, the operation is performed in Ansi.
The conversion rule used for Unicode systems is as follows:
  • If at least one of the strings is a buffer, all the strings are converted to buffers and the operation is performed with buffers.
  • Otherwise, the operation is performed in Unicode.
For more details on UNICODE, see Managing UNICODE.
Reminder: The linguistic parameters used are defined during the call to ChangeCharset.
Component: wd290vm.dll
Minimum version required
  • Version 9
This page is also available for…
Comments
Exemplo
Eu faria assim:

ArrNomes is array of string
X is Int=0
N_exclama is int = stringcount(texto, “!”)
Nome is string
Loop(N_exclama)
X++
Nome=extractString(texto, x, “!”) //começo pro fim
Add(ArrNomes, Nome)
End
Boller
28 Nov. 2023

Last update: 07/03/2023

Send a report | Local help