Modify ↓
#1879 closed Feature Request (Rejected)
StringCount()
| Reported by: | mvg | Owned by: | |
|---|---|---|---|
| Milestone: | Component: | AutoIt | |
| Version: | Severity: | None | |
| Keywords: | StringCount string count | Cc: |
Description
StringCount ( "string", "searchstring" [, casesense]] )
return value: occurrence of searchstring
No need to use:
- 1) StringReplace @extended.
dim $count = StringCount($string1,$searchstring) + StringCount($string2,$searchstring) + ...
instead of
dim $count = 0 StringReplace($string1, $searchstring, $searchstring) $count += @extended StringReplace($string2, $searchstring, $searchstring) $count += @extended ...
- 2) or StringRegExp(). (slow compared to StringReplace() used example.)
Attachments (0)
Change History (3)
comment:1 by , 15 years ago
comment:2 by , 15 years ago
| Resolution: | → Rejected |
|---|---|
| Status: | new → closed |
comment:3 by , 15 years ago
In that case, minimal UDF to do the job.
(In case someone has the same idea/request)
#cs StringCount Counts substrings in a string. StringCount ( "string", "searchstring", [, casesense=0] ) Parameters string: The string to evaluate. searchstring: The substring to search for. casesense [optional] Flag to indicate if the operations should be case sensitive. 0 = not case sensitive, using the user's locale (default) 1 = case sensitive 2 = not case sensitive, using a basic/faster comparison Return Value Returns the number of substrings found. Remarks If the searchstring is empty, @error is set to 1. #ce Func StringCount($sString, $sSearch, $iCase = 0) If Not IsString($sSearch) Then $sSearch = String($sSearch) ;; mainly to block StringReplace() 'Start from' mode. StringReplace($sString, $sSearch, $sSearch, 0, $iCase) Return SetError(@error, 0, @extended) EndFunc
Note:
See TracTickets
for help on using tickets.

or (mixing StringReplace() and StingInStr() options)