我为什么要修剪'修剪'未使用此VB.NET代码声明?

时间:2016-11-30 21:36:23

标签: vb.net visual-studio-2013 trim

我正在尝试编译VB.NET应用程序。除了" elephant in the room",我还得到7" '修剪'未被宣布"像这样的代码错误:

enter image description here

......还有一个"' IsNothing'没有宣布。由于其保护级别,它可能无法访问。"在这一行:

If IsNothing(memberList) = False Then

我不了解VB,所以可能有一个简单的解决方案,但我不知道问题是什么。

4 个答案:

答案 0 :(得分:3)

Trim函数需要从程序集 Visual Basic运行时库(在Microsoft.VisualBasic.dll中)引用 Microsoft.VisualBasic

通常最好使用字符串类中的本机Trim方法,而不是添加对此程序集的引用(主要用于帮助移植旧的VB6应用程序)

mail.CC.Add(addr.Trim())

另请注意,string.Trim会删除其他空白字符作为选项卡,而Microsoft.VisualBasic函数则不会。

答案 1 :(得分:1)

您必须使用addr.Trim代替Trim(addr)

在此MSDN article

中详细了解Trim

你应该使用

If not memberList Is Nothing Then

而不是

If IsNothing(memberList) = False Then

您必须导入Microsoft.VisualBasic命名空间

答案 2 :(得分:1)

如果您使用Left()Mid()Right()字符串函数,您可能会发现更容易转换它们:

Left(t, l)变为t.Substring(0, l)

Mid(t, s, l)变为t.Substring(s-1, l)

Right(t, l)变为t.Substring(t.Length - l)

通常LeftRight是属性并阻止您使用旧的VB字符串函数。

答案 3 :(得分:0)

String.Trim不接受字符串参数。它返回一个新字符串,其中删除当前String对象中一组指定字符的所有前导和尾随出现。

应该是......

 addr.Trim()
相关问题