Skip to content

Commit 1300b43

Browse files
committed
documented count function
1 parent 579a95a commit 1300b43

File tree

1 file changed

+55
-3
lines changed

1 file changed

+55
-3
lines changed

doc/specs/stdlib_strings.md

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ end program demo_slice
280280
Returns the starting index of the `occurrence`th occurrence of the substring `pattern`
281281
in the input string `string`.
282282
Default value of `occurrence` is set to `1`.
283-
If `consider_overlapping` is not provided or is set to `.true.` the function counts two overlapping occurrences of substring as two different occurrences.
283+
If `consider_overlapping` is not provided or is set to `.true.` the function counts two overlapping occurrences of substring `pattern` as two different occurrences.
284284
If `occurrence`th occurrence is not found, function returns `0`.
285285

286286
#### Syntax
@@ -308,7 +308,7 @@ Elemental function
308308

309309
#### Result value
310310

311-
The result is a scalar of integer type or integer array of rank equal to the highest rank among all dummy arguments.
311+
The result is a scalar of integer type or an integer array of rank equal to the highest rank among all dummy arguments.
312312

313313
#### Example
314314

@@ -381,4 +381,56 @@ program demo_replace_all
381381
! string <-- "technology here, technology there, technology everywhere"
382382
383383
end program demo_replace_all
384-
```
384+
```
385+
386+
387+
<!-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -->
388+
### `count`
389+
390+
#### Description
391+
392+
Returns the number of times substring `pattern` has occurred in the input string `string`.
393+
If `consider_overlapping` is not provided or is set to `.true.` the function counts two overlapping occurrences of substring `pattern` as two different occurrences.
394+
395+
#### Syntax
396+
397+
`string = [[stdlib_strings(module):count(interface)]] (string, pattern [, consider_overlapping])`
398+
399+
#### Status
400+
401+
Experimental
402+
403+
#### Class
404+
405+
Elemental function
406+
407+
#### Argument
408+
409+
- `string`: Character scalar or [[stdlib_string_type(module):string_type(type)]].
410+
This argument is intent(in).
411+
- `pattern`: Character scalar or [[stdlib_string_type(module):string_type(type)]].
412+
This argument is intent(in).
413+
- `consider_overlapping`: logical.
414+
This argument is intent(in) and optional.
415+
416+
#### Result value
417+
418+
The result is a scalar of integer type or an integer array of rank equal to the highest rank among all dummy arguments.
419+
420+
#### Example
421+
422+
```fortran
423+
program demo_count
424+
use stdlib_string_type, only: string_type, assignment(=)
425+
use stdlib_strings, only : count
426+
implicit none
427+
type(string_type) :: string
428+
429+
string = "How much wood would a woodchuck chuck if a woodchuck could chuck wood?"
430+
431+
print *, count(string, "wood") ! 4
432+
print *, count(string, ["would", "chuck", "could"]) ! [1, 4, 1]
433+
print *, count("a long queueueueue", "ueu", [.false., .true.]) ! [2, 4]
434+
435+
end program demo_count
436+
```

0 commit comments

Comments
 (0)