函数匹配括号'('和')' [英] function to match parenthesis '(' and ')'

查看:95
本文介绍了函数匹配括号'('和')'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个简单的函数,它可以匹配表达式中开头和结尾

括号的数量。这是一个示例表达式:


((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.

推荐答案

" Steve Kirsch" < TE ** @ test.com>写道:
"Steve Kirsch" <te**@test.com> wrote:
我需要一个简单的函数,它可以匹配表达式中起始和结束括号的数字。
这是一个示例表达式:
((" john")和(" jane")和(" joe"))
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" ) )




框架中没有任何内容需要计算字符串中出现

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.


Salam


这个问题的简单解决方案是实现一个堆栈,当你遇到'''''''把它推到堆栈上时,当你遇到'')''时,将它从

的堆栈中弹出。


在最后,检查stach是否为空,如果是空,然后括号

匹配,否则他们不是。


-

ALI RAZA SHAIKH

MCAD.net

www.programmersparadise.cjb.net

alirazashaikh.blogspot.com

" Steve Kirsch" < TE ** @ test.com>在留言中写道

新闻:%2 **************** @ TK2MSFTNGP15.phx.gbl ...
Salam

The simple solution to this problem is to implement a stack, when u
encounter ''('' push it on the stack, and when u encounter '')'', pop it from
the stack.

In the End, check if the stach is empty, if it is empty then the parenthesis
are match else they are not.

--
ALI RAZA SHAIKH
MCAD.net

www.programmersparadise.cjb.net
alirazashaikh.blogspot.com
"Steve Kirsch" <te**@test.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
我需要一个简单的函数,可以匹配表达式中的开始和结束括号的数量。这是一个示例表达式:

((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.



Salam


这个简单的解决方案问题是实现一个堆栈,当你遇到''(''把它推到堆栈上,当你遇到'')''时,弹出来自

堆栈。


在最后,检查stach是否为空,如果它是空的,则括号

匹配,否则它们不匹配。 />
-

ALI RAZA SHAIKH

MCAD.net

www.programmersparadise.cjb.net

alirazashaikh.blogspot.com


" Steve Kirsch" < TE ** @ test.com>在留言中写道

新闻:%2 **************** @ TK2MSFTNGP15.phx.gbl ...
Salam

The simple solution to this problem is to implement a stack, when u
encounter ''('' push it on the stack, and when u encounter '')'', pop it from
the stack.

In the End, check if the stach is empty, if it is empty then the parenthesis
are match else they are not.
--
ALI RAZA SHAIKH
MCAD.net

www.programmersparadise.cjb.net
alirazashaikh.blogspot.com

"Steve Kirsch" <te**@test.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
我需要一个简单的函数,可以匹配表达式中的开始和结束括号的数量。这是一个示例表达式:

((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.



这篇关于函数匹配括号'('和')'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆