函数匹配括号'('和')'

编程入门 行业动态 更新时间:2024-10-09 13:25:11
本文介绍了函数匹配括号'('和')'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要一个简单的函数,它可以匹配表达式中开头和结尾 括号的数量。这是一个示例表达式: ((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.

更多推荐

函数匹配括号'('和')'

本文发布于:2023-11-29 02:28:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1644938.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:括号   函数

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!