gtool5 Fortran 90/95 ライブラリ 1.0.0-rc5
English
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 
)

文字列の置換

文字列 str に文字列 from が含まれる場合、その部分を文字列 to に置換して返します。 文字列 from が含まれない場合は str をそのまま返します。 from が複数含まれる場合、先頭の from のみが置換されます。 全ての from を to へ変換したい場合には、 オプショナル引数 recursive に .true. を与えてください。 デフォルトでは、文字列の最初から検索を行います。 オプショナル引数 start_pos を与える場合、start_pos 文字目から検索を行います。

Parameters
[in]str元の文字列
[in]from検索する文字列
[in]to置換後の文字列
[in]recursive.true.の場合、全ての出現箇所を置換(省略可能)
[in]start_pos検索開始位置(省略可能)
Returns
置換後の文字列

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
種別型パラメタを提供します。
Definition dc_types.f90:55
integer, parameter, public sp
単精度実数型変数
Definition dc_types.f90:82
integer, parameter, public 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: