使用腳本處理字符串,前後增加“”

性能測試中經常要對報文拼接,而提供對報文可能xml,但是腳本中經常使用的字符串,需要增加""處理

如下腳本功能:就是實現增加雙引號功能

此腳本使用VBscript語言,在windows環境中,新建一個test.vbs文件,內容如下:


Option Explicit
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Dim fso,file,file1,msg,outmsg
Set fso = CreateObject("Scripting.FileSystemObject")
Set file = fso.OpenTextFile("input.txt",ForReading)
Set file1 = fso.OpenTextFile("output.txt",ForWriting)
Do While Not file.AtEndofStream
msg =file.Readline
msg =trim(msg)
msg =replace(msg,"""","\""",1,-1,1)
outmsg=""""&msg&""""
file1.WriteLine outmsg
loop
file1.Close
file.Close
Set file1=nothing
Set file = nothing
Set fso = nothing


3.在腳本目錄下,新建input.txt文件,此文件中保存報文


4.運行腳本.vbs文件,產生處理好的字符串格式的報文,保存在output.txt文件


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章