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 }

Mohsen Sarkar
  • 5,910
  • 7
  • 47
  • 86
  • 1
    Don't parse source code using regular expressions. That's just as bad as parsing HTML with regexes. – ThiefMaster Mar 15 '13 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](http://regex.info/blog/2006-09-15/247)" – MattW Mar 15 '13 at 12:37

1 Answers1

4

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

Community
  • 1
  • 1
Knaģis
  • 20,827
  • 7
  • 66
  • 80