最終更新日 : 
                
                    2021年4月28日
                
            
            
        
        
    
ReplaceList(string, list1, list2,includeEmptyFields) ReplaceList(string, list1, list2, delimiter, includeEmptyFields) ReplaceList(string, list1, list2, delimiter_list1, delimiter_list2, includeEmptyFields)
関連項目
パラメーター
パラメーター  | 
    説明  | 
   
|---|---|
string  | 
    置き換えを実行する対象の部分文字列、またはそのような部分文字列を含んでいる変数です。  | 
   
list1  | 
    検索する部分文字列を指定するカンマ区切りリストです。  | 
   
list2  | 
    部分文字列を置き換える文字列を指定するカンマ区切りリストです。  | 
   
delimiter  | 
    検索と置き換えの両方に使用する共通の区切り文字です。  | 
   
delimiter_list1  | 
    検索用の区切り文字です。  | 
   
delimiter_list2  | 
    置き換え用の区切り文字です。  | 
   
includeEmptyFields  | 
    true の場合、空のリスト要素が保持されます。  | 
   
使用方法
検索する部分文字列のリストは、先頭の要素から順番に処理されます。list1 に含まれる要素のいずれかの内容が list2 の要素内にも出現する場合、再帰的な置換処理が発生する可能性があります。そのような例を次に示します。
例
<p>The ReplaceList function returns <I>string</I> with 
<I>substringlist1</I> (e.g. "a,b") replaced by <I>substringlist2</I> 
(e.g. "c,d") in the specified scope. 
<cfif IsDefined("FORM.MyString")> 
<p>Your original string, <cfoutput>#FORM.MyString#</cfoutput> 
<p>You wanted to replace the substring <cfoutput>#FORM.MySubstring1# 
</cfoutput> 
with the substring <cfoutput>#FORM.MySubstring2#</cfoutput>. 
<p>The result: <cfoutput>#Replacelist(FORM.myString, 
FORM.MySubstring1, FORM.mySubString2)#</cfoutput> 
</cfif> 
<form action = "replacelist.cfm" method="post"> 
<p>String 1 
<br><input type = "Text" value = "My Test String" name = "MyString"> 
<p>Substring 1 (find this list of substrings) 
<br><input type = "Text" value = "Test, String" name = "MySubstring1"> 
<p>Substring 2 (replace with this list of substrings) 
<br><input type = "Text" value = "Replaced, Sentence" name = "MySubstring2"> 
<p><input type = "Submit" value = "Replace and display" name = ""> 
</form> 
<h3>Replacelist Example Two</h3> 
<cfset stringtoreplace = "The quick brown fox jumped over the lazy dog."> 
<cfoutput> 
#ReplaceList(stringtoreplace,"dog,brown,fox,black", "cow,black,ferret,white")# 
</cfoutput>
		
	
両方のリストに区切り文字を使用する例
<h3>Replacelist Example One</h3> <cfset stringtoreplace = "The quick brown fox jumped over the lazy dog."> <cfoutput> #ReplaceList(stringtoreplace,"dog:brown:fox:black", "cow:black:ferret:white", ":")# </cfoutput>
この例は、次の文字列を返します。
The quick white ferret jumped over the lazy cow.
個々のリストに固有の区切り文字を使用する例
<h3>Replacelist Example Two</h3> <cfset stringtoreplace = "The quick brown fox jumped over the lazy dog."> <cfoutput> #ReplaceList(stringtoreplace,"dog:brown:fox:black", "cow-black-ferret-white", ":" , "-")# </cfoutput>
この例は、次の文字列を返します。
The quick white ferret jumped over the lazy cow.
includeEmptyFields = true の例
<h3>Example when includeEmptyFields is true</h3> 
<cfset stringtoreplace = "The quick brown fox jumped over the lazy dog."> 
<cfoutput>
       #ReplaceList(stringtoreplace, "dog:brown:fox:black", "--black-ferret-white", ":", "-", true)#
</cfoutput>
		
	
この例は、次の文字列を返します。
The quick ferret jumped over the lazy .
includeEmptyFields = false の例
<h3>Example when includeEmptyFields is false</h3> 
<cfset stringtoreplace = "The quick brown fox jumped over the lazy dog.">
<cfoutput>
       #ReplaceList(stringtoreplace, "dog:brown:fox:black", "--black-ferret-white", ":", "-", false)#
</cfoutput>
		
	
この例は、次の文字列を返します。
The quick ferret white jumped over the lazy .