加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

通过VB.NET中的字符串中的字符循环

发布时间:2020-12-17 00:27:37 所属栏目:大数据 来源:网络整理
导读:我正在忙于在过去的考试文件中准备Visual Basic考试.我需要帮助我解决以下问题. Write a function procedure to calculate the number of times the characters “e”,“f” and “g” appears in a string 我试图写出psuedo代码,并提出了以下. Loop through
我正在忙于在过去的考试文件中准备Visual Basic考试.我需要帮助我解决以下问题.

Write a function procedure to calculate the number of times the characters “e”,“f” and “g” appears in a string

我试图写出psuedo代码,并提出了以下.

Loop through each individual character in the string
If the character = "e","f" or "g" add 1 to number of characters
Exit loop 
Display total in messagebox

如何循环使用字符串中的各个字符(使用for循环),如何计算特定字符在字符串中出现的次数?

答案很大程度上取决于你在课程中已经学到了什么,你应该使用哪些功能.

但是一般来说,循环字符串中的字符就像这样简单:

Dim s As String = "test"

For Each c As Char in s
    ' Count c
Next

至于计数,只需要为每个字符分别设置单独的计数器变量(eCount As Integer等),并在c等于该字符时增加它们 – 显然,一旦增加要计数的字符数,该方法就不会很好地缩放.这可以通过维护相关字符的字典来解决,但我猜测这对你的锻炼来说太先进了.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读