开发教室
程序设计|Delphi|Java|C++|VB|.NET|Css|Js|PHP|ASP|MySQL|数据库|WEB开发|网页特效|视频
首页 > 开发教室 > 程序设计 > VB > 正文

使用VB6的Split函数计算子串

2007-04-10 源自: 网友评论 0 进入视频教程

  Use the Visual Basic 6.0 Split function to count substrings

As we mentioned in a previous tip, Visual Basic 6.0 introduced the Split function, which provides a new way to parse strings. With it, you indicate a delimiter within a string, and Visual Basic fills a one-dimensional array with the substrings.

However, in addition to the functionality described above, you can also use the Split function as a quick way to determine the number of substrings within a larger string. For example, suppose you want to determine the number of times 注释:sea注释: appears in the string "She sells seashells by the seashore." To do so, simply perform the split, and use the UBound function to count the number of elements in the resultant array, as in

strTungTied = "She sells seashells by the seashore."
arySea = Split(strTungTied, "sea")
MsgBox "注释:Sea注释: appears in 注释:" & strTungTied _
& "注释: " & UBound(arySea) & " times."

When you run this code snippet, Visual Basic informs you that 注释:sea注释: appears in the phrase twice.

上一篇: 利用VB6.0开发基于IIS的应用程序
下一篇:一个简单地vb开发多媒体播放器软件的方法 适用初学者 mci

评论  点击查看
 
开发频道推荐
开发热点文章