Click here to Skip to main content
12,698,775 members (27,278 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# ASP.NET
Hi all

I have a string like this:
string abc = "  /*some 10 lines of code */   
    // Program Begin
          //Some Code Here
          //Some Code Here
          //Some Code Here
          //Some Code Here
          //Some Code Here
    // Program End
    //some liens of code
    //some liens of code";

I want only the code between "// Program Begin" and "// Program End".

How to do this.
I searched in Google and not get any effective result.

Please Help

Thanks in advance.
Posted 10-Oct-12 2:38am
Updated 10-Oct-12 2:43am
Andy411 10-Oct-12 7:43am
Do you have only these two parenthesis { and } ? Then search for the Index of both and copy the part between the indexes.
MAC123456 10-Oct-12 7:46am
No there may be more in the code
Andy411 10-Oct-12 7:50am
You need something unique at the opening parentesis of the code block you are interested in to find it.
biswarup88 10-Oct-12 7:49am
question is not clear.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You can find the index of your start element and end element by using System.String.IndexOf("// Program Begin") and
System.String.IndexOf("// Program End")
details here[^]
Then you can do a System.String.Substring(firstIndex, numberOfcharacters)
details here[^]
The numberOfCharacters can be retrieved by subtracting both indexes in the right order.

Good luck!
MAC123456 10-Oct-12 9:49am

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170118.1 | Last Updated 10 Oct 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100