如何计算字符串中的单词数?网络 [英] How to count the number of words in a string? vb.net

查看:28
本文介绍了如何计算字符串中的单词数?网络的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿伙计们,我需要一些帮助.在 Visual Basic 中,我使用什么表达式来计算用户输入字符串中的单词数?它需要在不使其成为数组的情况下完成.

Hey guys I need some help. What expression do I use to count the number of words in a user-inputted string in Visual Basic? It needs to be done without making it an array.

推荐答案

Public Function CountWords(ByVal value As String) As Integer

' Count matches.
Dim collection As MatchCollection = Regex.Matches(value, "\S+")
Return collection.Count

End Function

这篇关于如何计算字符串中的单词数?网络的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆