0

こんにちは、引用符のようなものやそのようなものを含むファイルに複数の行を書き込む簡単な方法はありますか、またはこのようにする唯一の方法です

                Dim objwriter As New System.IO.StreamWriter(AppsDir & "EthIPChanger.bat")
            objwriter.WriteLine("@echo off")
            objwriter.WriteLine("netsh interface ip set address name=""" & "Local Area Connection""" & " static " & TB_EthIPAddress.Text & " " & TB_EthSubnetMask.Text & " " & TB_EthDefaultGateway.Text & " 1")
            objwriter.WriteLine("netsh interface ip set dns """ & "Local Area Connection""" & " static " & TB_EthDNS1.Text)
            objwriter.WriteLine("ipconfig /all > """ & AppsDir & "NetworkInfo.txt""")
            objwriter.WriteLine("echo hi > """ & AppsDir & "CheckLen.txt""")
            objwriter.Close()

Pythonを使用している場合は、「」を実行してから、その内部で何かを実行して「」で終了できることを知っています

そのようなものはvb.netに存在しますか?

ありがとう

4

2 に答える 2

2

objwriter.Write を使用すると、vbcrlf を自分で指定でき、1 つの書き込みステートメントに複数の「行」を入れることができます。

例えば:

Dim str2write As string
str2write  = "firstline" and Chr(34) & Chr(34) & vbcrlf
str2write &= Chr(34) & "second line" and Chr(34) & vbcrlf & vbcrlf
objwriter.write(str2write)
objwriter.close()
于 2012-08-14T21:31:03.920 に答える
1

StringBuilder で試すことができます。

    Dim objwriter As New System.IO.StreamWriter(AppsDir & "EthIPChanger.bat")
    Dim textToWrite As New System.Text.StringBuilder

    With textToWrite
        .Append("@echo off")
        .AppendFormat("netsh interface ip set address name={0}Local Area Connection{0} static {1} {2} {3} 1", Chr(34), TB_EthIPAddress.Text, TB_EthSubnetMask.Text, TB_EthDefaultGateway.Text)
        .AppendFormat("netsh interface ip set dns {0}Local Area Connection{0} static {1}", Chr(34), TB_EthDNS1.Text)
        .AppendFormat("ipconfig /all > {0}{1}{2}{0}", Chr(34), AppsDir, TB_EthDNS1.Text)
        .AppendFormat("echo hi > {0}{1}{2}{0}", Chr(34), AppsDir, CheckLen.Text)
    End With

    objwriter.WriteLine(textToWrite.ToString)
    objwriter.Close()
于 2012-08-14T21:29:56.553 に答える