代码之家  ›  专栏  ›  技术社区  ›  Vibin Jith

这个vb.net子字符串调用有什么问题?

  •  0
  • Vibin Jith  · 技术社区  · 16 年前
     dim dataType as String
      toolTip="Marks And Number[String]"
    

    我想单独拿那根绳子。

      dataType = toolTipText.Substring(toolTipText.IndexOf("[") + 1, toolTipText.IndexOf("]") - 1)
    

    它显示一个错误。关于绳子的长度。

    我的代码怎么了。我不知道, 有时候我会遇到这样的问题。以简单的循环或条件站立。

    2 回复  |  直到 14 年前
        1
  •  4
  •   David M    16 年前

    第二个参数是长度,而不是结束索引。你需要从中减去你的起始指数。

        2
  •  2
  •   PaulB    16 年前

    不是说这是很棒的代码,而是

    dataType = toolTip.Substring(toolTip.IndexOf("[") + 1, toolTip.Length - toolTip.IndexOf("[") - 2)
    

    会帮你解决的。

    第二个参数是子字符串的长度,而不是结束索引。

    最好看看regex。