Skip to content

Commit d855fcd

Browse files
committed
documented function find
1 parent 71da64c commit d855fcd

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

doc/specs/stdlib_strings.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,3 +270,62 @@ program demo_slice
270270
271271
end program demo_slice
272272
```
273+
274+
275+
<!-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -->
276+
### `find`
277+
278+
#### Description
279+
280+
Returns the starting index of the `occurrence`th occurrence of the substring `pattern`
281+
in the input string `string`.
282+
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 occurences of substring as two different occurrences.
284+
If `occurrence`th occurrence is not found, function returns `0`.
285+
286+
287+
#### Syntax
288+
289+
`string = [[stdlib_strings(module):find(interface)]] (string, pattern, occurrence, consider_overlapping)`
290+
291+
#### Status
292+
293+
Experimental
294+
295+
#### Class
296+
297+
Pure function
298+
299+
#### Argument
300+
301+
- `string`: Character scalar or [[stdlib_string_type(module):string_type(type)]]
302+
This argument is intent(in).
303+
- `pattern`: Character scalar or [[stdlib_string_type(module):string_type(type)]]
304+
This argument is intent(in).
305+
- `occurrence`: integer
306+
This argument is intent(in) and optional.
307+
- `consider_overlapping`: logical
308+
This argument is intent(in) and optional.
309+
310+
#### Result value
311+
312+
The result is of scalar integer type.
313+
314+
#### Example
315+
316+
```fortran
317+
program demo_find
318+
use stdlib_string_type
319+
use stdlib_strings, only : find
320+
implicit none
321+
string_type :: string
322+
323+
string = "needle in this character-stack"
324+
325+
print *, find(string, "needle") ! 1
326+
print *, find(string, "a", 3) ! 28
327+
print *, find("qwqwqwq", "qwq", 3, .false.) ! 0
328+
print *, find("qwqwqwq", "qwq", 3, .true.) ! 5
329+
330+
end program demo_find
331+
```

0 commit comments

Comments
 (0)