1

I want a easy solution to get part of string in C#.
The string structure is like C++ blocks.

class aaa{ void bbb(){ ccc {...} text1 } text2}

The string I want is to get a specified block of code like following.

string.blocks.second() : which should return :
{ ccc {...} text1 }

2
  • 1
    Don't parse source code using regular expressions. That's just as bad as parsing HTML with regexes. Commented Mar 15, 2013 at 12:30
  • @ThiefMaster is right - any grammar that includes nested structures, like the {} in C-like languages, is ill-suited to parsing by regular expressions. In many regex dialects, it's impossible; in the .NET dialect it's possible but difficult to do, difficult to read, difficult to debug, and really slow. A classic example of "now you have two problems" Commented Mar 15, 2013 at 12:37

1 Answer 1

4

Since you are talking about source code, you should look at C-like language parsers. They are discussed here: Parser for C#

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.