在连接字符串时获取空格

时间:2013-12-19 10:26:48

标签: vb.net vb.net-2010

我正在尝试将字符串变量连接到另一个字符串但我在变量之前和之后不断获得空格

objwriter.WriteLine("netsh int ipv4 Set address "+adaptername+" dhcp")

输出如下

netsh int ipv4 Set address  Wi-Fi  dhcp

我已经尝试了以下方法来连接字符串

objwriter.WriteLine("netsh int ipv4 Set address "& adaptername &" dhcp") objwriter.WriteLine("netsh int ipv4 Set address "" & adaptername & "" dhcp")

2 个答案:

答案 0 :(得分:2)

objwriter.WriteLine("netsh int ipv4 Set address " & adaptername.Trim() & " dhcp")

答案 1 :(得分:2)

尝试

<强> VB.Net

objwriter.WriteLine("netsh int ipv4 Set address " &  adaptername.Trim() & " dhcp")

C#

objwriter.WriteLine("netsh int ipv4 Set address " +  adaptername.Trim() + " dhcp");