且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在VB.NET中获取字符串中出现的字符数

更新时间:2022-11-07 23:21:56

看看这个:计算字符串中的行数 [ ^ ] - 它是关于行的,但这只是意味着它专门寻找'\ n' - 改变它很简单 - 代码是C#而不是VB,但它主要是非常简单的代码。如果您无法理解,那么这样的在线转换器可能有所帮助:代码转换器C#到VB和VB到C# - Telerik [ ^ ]

它提供了不同的方法它和它们的相对速度一起。
Have a look at this: Counting Lines in a String[^] - it's about lines, but that just means that it specifically looks for '\n' - it's simple to change that - and the code is C# rather than VB, but it's mostly pretty trivial code. If you can't understand it, then online converters like this may help: Code Converter C# to VB and VB to C# – Telerik[^]
It presents quite a few different ways to do it, together with their relative speeds.


引用:

但它不起作用。我甚至认为我的函数没有正确返回字符串。

but it dont work. I don't even think my function is returning the string properly.



显示你得到的结果可以帮助你知道函数是否正常工作。


Displaying the result you get may help you to know if the function works properly or not.

MyFunction([some arguments]).Replace("*", "").Count



替换是一个RegEx函数,在RegEx中,'*'是一个特殊的字符。你可能需要改变它吗'\ *'



只是一些有趣的链接来帮助建立和调试RegEx。

这里是RegEx文档的链接:

perlre - perldoc.perl.org [ ^ ]

以下是帮助构建RegEx的工具的链接并调试它们:

.NET正则表达式测试程序 - 正则表达式风暴 [ ^ ]

Expresso正则表达式工具 [ ^ ]

RegExr:Learn,Build,&测试RegEx [ ^ ]

在线正则表达式测试器和调试器:PHP,PCRE,Python,Golang和JavaScript [ ^ ]

这个显示RegEx是一个很好的图表,它非常有助于理解RegEx的作用:

Debuggex:在线可视正则表达式测试器。 JavaScript,Python和PCRE。 [ ^ ]

这个网站也在一个漂亮的图表中显示正则表达式,但无法测试与RegEx匹配的内容:

Regexper [ ^ ]


Replace is a RegEx function, and in RegEx , '*' is a special char. you probaly need to change it ti '\*'

Just a few interesting links to help building and debugging RegEx.
Here is a link to RegEx documentation:
perlre - perldoc.perl.org[^]
Here is links to tools to help build RegEx and debug them:
.NET Regex Tester - Regex Storm[^]
Expresso Regular Expression Tool[^]
RegExr: Learn, Build, & Test RegEx[^]
Online regex tester and debugger: PHP, PCRE, Python, Golang and JavaScript[^]
This one show you the RegEx as a nice graph which is really helpful to understand what is doing a RegEx:
Debuggex: Online visual regex tester. JavaScript, Python, and PCRE.[^]
This site also show the Regex in a nice graph but can't test what match the RegEx:
Regexper[^]