[ホーム] >
[VBScript FAQ 一覧] > [文字列置換の vbscript 用関数]
vbscriptで文字列置換を行う関数のサンプルです。
Function ReplaceSubstring(inputStr As String, fromStr As String, toStr As String) As String
Dim outputStr As String
Dim i As Integer
outputStr = inputStr
While Instr(outputStr, fromStr) > 0
i = Instr(outputStr, fromStr)
outputStr = Left$(outputStr, i - 1) & toStr & Right$(outputStr, Len(outputStr) - (i + Len(fromStr) - 1))
Wend
ReplaceSubstring = outputStr
End Function
(*)以下は呼び出し方の例です。(targetStrから改行を除去する場合)
targetStr=ReplaceSubstring (targetStr,Chr(10), "")
targetStr=ReplaceSubstring (targetStr,Chr(13), "")
[ホーム] >
[VBScript FAQ 一覧]