Click here to Skip to main content
Rate this: bad
good
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 1:38am
Mac123341.1K
Edited 10-Oct-12 1:43am
v4
Comments
Andy411 at 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 at 10-Oct-12 7:46am
   
No there may be more in the code
Andy411 at 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 at 10-Oct-12 7:49am
   
question is not clear.

1 solution

Rate this: bad
good
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!
  Permalink  
Comments
MAC123456 at 10-Oct-12 9:49am
   
Thanks

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

  Print Answers RSS
0 OriginalGriff 221
1 BillWoodruff 205
2 CPallini 199
3 Maciej Los 170
4 Kornfeld Eliyahu Peter 160


Advertise | Privacy | Mobile
Web01 | 2.8.141015.1 | Last Updated 10 Oct 2012
Copyright © CodeProject, 1999-2014
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