Click here to Skip to main content
Rate this: bad
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
Edited 10-Oct-12 2:43am
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
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 at 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
0 DamithSL 300
1 Zoltán Zörgő 170
2 OriginalGriff 150
3 Sergey Alexandrovich Kryukov 120
4 Maciej Los 115
0 OriginalGriff 7,740
1 DamithSL 5,769
2 Sergey Alexandrovich Kryukov 5,424
3 Maciej Los 5,076
4 Kornfeld Eliyahu Peter 4,539

Advertise | Privacy | Mobile
Web02 | 2.8.141223.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