Modify

Opened 15 years ago

Closed 15 years ago

Last modified 15 years ago

#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 mvg, 15 years ago

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

StringCount ( "string", "searchstring" [, casesense [, start [, count]]] )

comment:2 by Jon, 15 years ago

Resolution: Rejected
Status: newclosed

comment:3 by mvg, 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

Modify Ticket

Action
as closed The ticket will remain with no owner.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.