Validate a Boolean expression with brackets in C#

后端 未结 6 676
清歌不尽
清歌不尽 2021-01-18 01:12

I want to validate a string in C# that contains a Boolean expression with brackets. The string should only contain numbers 1-9, round brackets, \"OR\" , \"AND\".

Exa

6条回答
  •  遇见更好的自我
    2021-01-18 01:55

    what you want are "balanced groups", with them you can get all bracet definitions, then you just need a simple string parsing

    http://blog.stevenlevithan.com/archives/balancing-groups

    http://msdn.microsoft.com/en-us/library/bs2twtah.aspx#balancing_group_definition

提交回复
热议问题