[VB.NET]求救.速度.!帮忙写点东西.!
来源:互联网 发布:淘宝店铺转让 编辑:程序博客网 时间:2024/04/28 16:23
<script type="text/javascript"><!--google_ad_client = "pub-8333940862668978";/* 728x90, 创建于 08-11-30 */google_ad_slot = "4485230109";google_ad_width = 728;google_ad_height = 90;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
求救.速度.!帮忙写点东西.!
编写一个方法,统计输入的英语字符串有多少个英文单词组成.假设输入的字符串只用空格,逗号,句号分隔单词.方法的原形如下:
Public Function CountWords(ByVal input As String) As Integer
End Function
__________________________________________________________________________
Public Function CountWords(ByVal input As String) As Integer
Dim num As Int32 = 0
input = input.TrimStart( " ")
input = input.TrimEnd( " ")
input = input.Replace(vbCrLf, " ")
Dim sentences() As String = input.Split( ". ")
For Each sentence As String In sentences
If sentence.Length > 0 Then
sentence = sentence.TrimStart( " ")
sentence = sentence.TrimEnd( " ")
Dim clauses() As String = sentence.Split( ", ")
For Each clause As String In clauses
If clause.Length > 0 Then
clause = clause.TrimStart( " ")
clause = clause.TrimEnd( " ")
num += clause.Split( " ").GetUpperBound(0) + 1
End If
Next
End If
Next
Return num
End Function
__________________________________________________________________________
写得有点匆忙,只测试了几个句子,lz看能不能用吧。我是假设句子中不会出现换行符,换行符仅会出现在一句句子之后来做的。
__________________________________________________________________________
Public Function CountWords(ByVal input As String) As Integer
dim re as new Regex( "/w+ ")
dim mc as MatchCollection = re.Matches(input)
return mc.Count
End Function
__________________________________________________________________________
学习了,看来正则表达式还是好使,呵呵。
__________________________________________________________________________
正则表达式效率最好
__________________________________________________________________________
考虑用正则表达式来实现
__________________________________________________________________________
求救.速度.!帮忙写点东西.!
编写一个方法,统计输入的英语字符串有多少个英文单词组成.假设输入的字符串只用空格,逗号,句号分隔单词.方法的原形如下:
Public Function CountWords(ByVal input As String) As Integer
End Function
__________________________________________________________________________
Public Function CountWords(ByVal input As String) As Integer
Dim num As Int32 = 0
input = input.TrimStart( " ")
input = input.TrimEnd( " ")
input = input.Replace(vbCrLf, " ")
Dim sentences() As String = input.Split( ". ")
For Each sentence As String In sentences
If sentence.Length > 0 Then
sentence = sentence.TrimStart( " ")
sentence = sentence.TrimEnd( " ")
Dim clauses() As String = sentence.Split( ", ")
For Each clause As String In clauses
If clause.Length > 0 Then
clause = clause.TrimStart( " ")
clause = clause.TrimEnd( " ")
num += clause.Split( " ").GetUpperBound(0) + 1
End If
Next
End If
Next
Return num
End Function
__________________________________________________________________________
写得有点匆忙,只测试了几个句子,lz看能不能用吧。我是假设句子中不会出现换行符,换行符仅会出现在一句句子之后来做的。
__________________________________________________________________________
Public Function CountWords(ByVal input As String) As Integer
dim re as new Regex( "/w+ ")
dim mc as MatchCollection = re.Matches(input)
return mc.Count
End Function
__________________________________________________________________________
学习了,看来正则表达式还是好使,呵呵。
__________________________________________________________________________
正则表达式效率最好
__________________________________________________________________________
考虑用正则表达式来实现
__________________________________________________________________________
- [VB.NET]求救.速度.!帮忙写点东西.!
- [VB.NET]求救
- [VB.NET]vb.net 调用vb6.0写的ActiveX dll的问题,各位帮忙啊!
- [VB.NET]请大虾帮忙!!
- [VB.NET]求救线程下载程序
- [VB.NET]求救,if语句无效
- [VB.NET]帮忙写个select * from mydtata where (不麻烦的)
- 大家好这是我写的词典。很简单。我初学VB.NET请大家帮忙改进
- 写点东西先
- 写点东西
- 写点东西吧~~~~~~~~~~~~
- 第一次写点东西
- 第一次写点东西
- 开始写点东西
- 决定写点东西
- 写点东西
- 开始写点东西
- 开始 写点东西
- [VB.NET]MDI窗体
- [VB.NET]VB中有可以自动增加大小的类吗?
- [VB.NET]如何通过FileListBox在PictureBox显示图片!!!!
- Java编程那些事儿57—面向对象基础
- [VB.NET]将VB中文档写入Word时出现的错误,帮忙解决一下,谢谢
- [VB.NET]求救.速度.!帮忙写点东西.!
- [VB.NET]VB.NET生成的EXE文件在我的电脑上能运行,但是放到其他的电脑上就不行了?
- level set 介绍3
- [VB.NET]初始化PictureBox数组怎么操作
- [VB.NET]如何将TEXT中的文字导入到Word?知道的进下
- [VB.NET]winform ComboBox数据绑定问题
- level set 介绍4(水平集方法)
- 差分信号详解
- [VB.NET].NET精简框架下用VB.NET怎么实现在picturebox上显示不同图片???