问题描述
我需要一个简单的函数,它可以匹配表达式中开头和结尾
括号的数量。这是一个示例表达式:
((john)和(jane)和(joe))
.NET是否有内置功能可以完成此任务,或者我必须使用
编写自己的解析器吗?如果可能的话,我不想重新发明轮子。
I need a simple function that can match the number of beginning and ending
parenthesis in an expression. Here''s a sample expression:
( ( "john" ) and ( "jane" ) and ( "joe" ) )
Does .NET have something built-in that can accomplish this, or do I have to
write my own parser? I don''t want to reinvent the wheel if possible.
推荐答案
框架中没有任何内容需要计算字符串中出现
a字符的次数,但是你可以在
String.IndexOf中找到任何一个字符,并在循环中执行此操作以对它们进行全部计数。 (每次
你找到一个,增加起始位置并循环回来。)
P.
There''s nothing in the Framework to count the number of occurrences of
a character in a string, but you can find any one occurrence with
String.IndexOf, and do this in a loop to count them all. (Each time
you find one, increment the start position and loop back.)
P.
这篇关于函数匹配括号'('和')'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!