我需要一个简单的函数,它可以匹配表达式中开头和结尾 括号的数量。这是一个示例表达式: ((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>写道: "Steve Kirsch" <te**@test> 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 www.programmersparadise.cjb alirazashaikh.blogspot " Steve Kirsch" < TE ** @ test>在留言中写道 新闻:%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 www.programmersparadise.cjb alirazashaikh.blogspot "Steve Kirsch" <te**@test> 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 endingparenthesis 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 www.programmersparadise.cjb alirazashaikh.blogspot " Steve Kirsch" < TE ** @ test>在留言中写道 新闻:%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 www.programmersparadise.cjb alirazashaikh.blogspot "Steve Kirsch" <te**@test> 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 endingparenthesis 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.
更多推荐
函数匹配括号'('和')'
发布评论