在VB.NET中利用Split和Replace函数计算字数

开发者在线 Builder.com.cn 更新时间:2007-04-05作者:builder.com.cn 来源:

Private Sub CountWords()

        Dim strText As String = "It's a wonderful    world"
        Dim iCount As Integer

        Do While (strText.IndexOf(Space(2)) >= 0)
            strText = strText.Replace(Space(2), Space(1))
        Loop

        iCount = Split(strText, Space(1)).Length
        MsgBox(iCount.ToString())

    End Sub

用户评论

  • 用户名
  • 评论内容