Modify

Opened 9 years ago

Closed 9 years ago

Last modified 9 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 Changed 9 years ago by mvg

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

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

comment:2 Changed 9 years ago by Jon

  • Resolution set to Rejected
  • Status changed from new to closed

comment:3 Changed 9 years ago by mvg

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

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

Action
as closed The ticket will remain with no owner.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.