Activity Stream
48,167 MEMBERS
61032 ONLINE
besthostingforums On YouTube Subscribe to our Newsletter besthostingforums On Twitter besthostingforums On Facebook besthostingforums On facebook groups

Results 1 to 4 of 4
  1.     
    #1
    ლ(ಠ益ಠლ)
    Website's:
    extremecoderz.com

    Default [c#] Get String In between strings

    This static string will obtain a string in between 2 strings.

    For example. I have the string:

    Code: 
    <a href="myfile.php">foo-bar</a>
    If i wanted to get the name of the link (foo-bar):

    Code: 
    result = GetStringInbetween("\">", "</a>", sourceFile, false, false);
    string myString = result[0];
    the last two boolean values allow you to choose whether to include your beginning string and ending string with the result.

    Code: 
    
    string[] result;
    
    public static string[] GetStringInBetween(string strBegin, string strEnd, string strSource, bool includeBegin, bool includeEnd)
            {
                string[] result = { "", "" };
                int iIndexOfBegin = strSource.IndexOf(strBegin);
                if (iIndexOfBegin != -1)
                {
                    if (includeBegin)
                    { iIndexOfBegin -= strBegin.Length; }
                    strSource = strSource.Substring(iIndexOfBegin
                        + strBegin.Length);
                    int iEnd = strSource.IndexOf(strEnd);
    
                    if (iEnd != -1)
                    {
                        if (includeEnd)
                        { iEnd += strEnd.Length; }
                        result[0] = strSource.Substring(0, iEnd);
                        if (iEnd + strEnd.Length < strSource.Length)
                        { result[1] = strSource.Substring(iEnd + strEnd.Length); }
                    }
                }
                else
                { result[1] = strSource; }
                return result;
            }
    jayfella Reviewed by jayfella on . [c#] Get String In between strings This static string will obtain a string in between 2 strings. For example. I have the string: <a href="myfile.php">foo-bar</a> If i wanted to get the name of the link (foo-bar): result = GetStringInbetween("\">", "</a>", sourceFile, false, false); Rating: 5

  2.   Sponsored Links

  3.     
    #2
    Member
    Website's:
    litewarez.net litewarez.com triniwarez.com
    Would you be able to do a regex or a XML version of this

    What if we had <a href="myfile.php"><span class="foo">bar</span></a>

    would return bar</span> right
    Join Litewarez.net today and become apart of the community.
    Unique | Clean | Advanced (All with you in mind)
    Downloads | Webmasters


    Notifications,Forum,Chat,Community all at Litewarez Webmasters


  4.     
    #3
    ლ(ಠ益ಠლ)
    Website's:
    extremecoderz.com
    yes thats exactly what it would return in the example you gave yes.

    The XML parser i posted previously does what you need for XML. It gets/sets node values.

  5.     
    #4
    Respected Developer
    Quote Originally Posted by litewarez View Post
    Would you be able to do a regex or a XML version of this
    Never parse markup with regex's, ever. Jay's method is how it should be done. To fully parse XML you'd do that sort of magic with the help of a FSM.

    Edit:
    My bad . Actually you're right since this isn't meant to parse. But still if it can be done with string functions it should because they are a hell of a lot faster.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. C++ string search help needed
    By googleplus in forum Web Development Area
    Replies: 0
    Last Post: 12th May 2012, 04:42 PM
  2. php string - heredoc syntax
    By desiboy in forum Web Development Area
    Replies: 3
    Last Post: 16th Nov 2010, 05:15 PM
  3. Extracting data from a string
    By pankaj in forum Web Development Area
    Replies: 38
    Last Post: 6th Jul 2010, 01:38 PM
  4. Review Warez Strings!
    By InnoX in forum Site Reviews
    Replies: 4
    Last Post: 18th Jun 2010, 10:18 PM
  5. Replies: 13
    Last Post: 28th Oct 2009, 05:06 AM

Tags for this Thread

BE SOCIAL