Skip to content

Commit e2a75a4

Browse files
committed
documented replace_all function
1 parent 7035422 commit e2a75a4

File tree

1 file changed

+56
-2
lines changed

1 file changed

+56
-2
lines changed

doc/specs/stdlib_strings.md

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,6 @@ Default value of `occurrence` is set to `1`.
283283
If `consider_overlapping` is not provided or is set to `.true.` the function counts two overlapping occurrences of substring as two different occurrences.
284284
If `occurrence`th occurrence is not found, function returns `0`.
285285

286-
287286
#### Syntax
288287

289288
`string = [[stdlib_strings(module):find(interface)]] (string, pattern [, occurrence, consider_overlapping])`
@@ -318,7 +317,7 @@ program demo_find
318317
use stdlib_string_type, only: string_type, assignment(=)
319318
use stdlib_strings, only : find
320319
implicit none
321-
string_type :: string
320+
type(string_type) :: string
322321
323322
string = "needle in the character-stack"
324323
@@ -328,3 +327,58 @@ program demo_find
328327
329328
end program demo_find
330329
```
330+
331+
332+
<!-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -->
333+
### `replace_all`
334+
335+
#### Description
336+
337+
Replaces all occurrences of substring `pattern` in the input `string` with the replacement `replacement`.
338+
Occurrences overlapping on a base occurrence will not be replaced.
339+
340+
#### Syntax
341+
342+
`string = [[stdlib_strings(module):replace_all(interface)]] (string, pattern, replacement)`
343+
344+
#### Status
345+
346+
Experimental
347+
348+
#### Class
349+
350+
Pure function
351+
352+
#### Argument
353+
354+
- `string`: Character scalar or [[stdlib_string_type(module):string_type(type)]].
355+
This argument is intent(in).
356+
- `pattern`: Character scalar or [[stdlib_string_type(module):string_type(type)]].
357+
This argument is intent(in).
358+
- `replacement`: Character scalar or [[stdlib_string_type(module):string_type(type)]].
359+
This argument is intent(in).
360+
361+
#### Result value
362+
363+
The result is of the same type as `string`.
364+
365+
#### Example
366+
367+
```fortran
368+
program demo_replace_all
369+
use stdlib_string_type, only: string_type, assignment(=)
370+
use stdlib_strings, only : replace_all
371+
implicit none
372+
type(string_type) :: string
373+
374+
string = "hurdles here, hurdles there, hurdles everwhere"
375+
! string <-- "hurdles here, hurdles there, hurdles everwhere"
376+
377+
print '(a)', replace_all(string, "hurdles", "learn from")
378+
! "learn from here, learn from there, learn from everwhere"
379+
380+
string = replace_all(string, "hurdles", "technology")
381+
! string <-- "technology here, technology there, technology everywhere"
382+
383+
end program demo_replace_all
384+
```

0 commit comments

Comments
 (0)