gtool5 Fortran 90/95 Library 1.0.0-rc5
日本語
Loading...
Searching...
No Matches
Public Member Functions | List of all members
dc_string::replace Interface Reference

Public Member Functions

recursive character(string) function replace (str, from, to, recursive, start_pos)
 

Detailed Description

Definition at line 178 of file dc_string.f90.

Constructor & Destructor Documentation

◆ replace()

recursive character(string) function dc_string::replace::replace ( character(*), intent(in)  str,
character(*), intent(in)  from,
character(*), intent(in)  to,
logical, intent(in), optional  recursive,
integer, intent(in), optional  start_pos 
)

Replace substring in string

If string from is included in str, replaces it with string to and returns. If from is not included, returns str without change. When multiple from are included, only the first one is replaced. To replace all from to to, give .true. to optional argument recursive. By default, the string is searched from the top. If optional argument start_pos is given, the search starts from start_pos.

Parameters
[in]strSource string
[in]fromString to find
[in]toReplacement string
[in]recursiveIf .true., replace all occurrences (optional)
[in]start_posStarting position for search (optional)
Returns
Replaced string

Definition at line 1658 of file dc_string.f90.

1660 use dc_types, only: string
1661 implicit none
1662 character(STRING):: result
1663 character(*), intent(in):: str, from, to
1664 logical, intent(in), optional:: recursive
1665 integer, intent(in), optional:: start_pos
1666 integer:: sp
1667 integer:: i, isa, isb, iea, ieb
1668 integer:: ir
1669 continue
1670 if ( present(start_pos) ) then
1671 sp = start_pos
1672 else
1673 sp = 1
1674 end if
1675 if ( sp < 1 ) then
1676 sp = 1
1677 end if
1678 result = str
1679 i = index(result(sp:), from)
1680 if (i == 0) return
1681 i = i + sp - 1
1682 isa = i + len(from)
1683 isb = i + len(to)
1684 if (len(to) < len(from)) then
1685 iea = len(result)
1686 ieb = len(result) + len(to) - len(from)
1687 else
1688 iea = len(result) + len(from) - len(to)
1689 ieb = len(result)
1690 endif
1691 if (len(to) /= len(from)) result(isb:ieb) = result(isa:iea)
1692 result(i:i+len(to)-1) = to
1693 !-----------------------------------
1694 ! 再帰的処理
1695 ! Recursive process
1696 ir = index(result(i+len(to):), from)
1697 if ( len_trim(from) == 0 ) then
1698 ir = index(trim(result(i+len(to):)), from)
1699 end if
1700 if (ir /= 0) then
1701 if ( present(recursive) ) then
1702 if ( recursive ) then
1703 result = replace( str = result, &
1704 & from = from, to = to, &
1705 & recursive = recursive, &
1706 & start_pos = i+len(to) )
1707 end if
1708 end if
1709 end if
Provides kind type parameter values.
Definition dc_types.f90:55
integer, parameter, public sp
Single Precision Real number.
Definition dc_types.f90:82
integer, parameter, public string
Character length for string
Definition dc_types.f90:137

References dc_types::sp, and dc_types::string.


The documentation for this interface was generated from the following file: