2012-08-14 35 views
0

嗨报价是否有写在具有类似的事情在报价和类似的其他东西或者是不喜欢这样写多行,在一个文本文件vb.net

的唯一办法把一个文件多行任何更简单的方法
   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存在吗?

感谢

+0

您可以使用* CHR(34)*而不是做双引号。 – 2012-08-14 20:47:16

回答

2

如果使用objwriter.Write - 那么你可以提供vbcrlf自己 - 然后你可以把多个“行”在一个写声明。

例如:

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() 
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() 
相关问题