SPONSORS:






User Tag List

Results 1 to 3 of 3
  1. #1
    Member
    Join Date
    Jul 2000
    Location
    sanjose,CA,USA
    Posts
    68
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Searching for a specific text

    1. I grab a text and search for a specific text which starts with =" and ends with ")
    2. The specific text I am looking is not of same length for all results,
    3. stext1 = Your search, (Subject="Athletes"), returned the following results:
    stext2 = Your search, (Subject="Media Violence"), returned the following results:
    4. From above results I am expecting to print only Athletes and Media Violence
    5. I used substr(stext1,strpos("=",stext1)+2,strpos(")",stex t1)) and substr(stext2,strpos("=",stext2)+2,strpos(")",stex t2))
    6. It printed the text from starting point but however displayed extra text
    7. I am looking for a function which work for all 100 stext (stext1,stext2......stext100)
    Can anyone give me a valuable suggestion

  2. #2
    Senior Member
    Join Date
    Feb 2000
    Posts
    1,497
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Searching for a specific text

    The trailing information is due to subtleties with string manipulation using single and double quotes and how both can be made to appear ("escaped" is the common term) into a normal string.

    Copy and run this example, then look carefully at its structure.

    </font><blockquote><font size="1" face="Verdana, Arial, Helvetica">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">main()
    {
    string stext1 = 'Your search, (Subject=&quot;Athletes&quot, returned the following results:' ;
    string stext2 = 'Your search, (Subject=&quot;Media Violence&quot, returned the following results:' ;
    int start, end ;
    string sTemp ;

    // Show what's going on one step at a time.
    start = strpos(&quot;=&quot;&quot;&quot;,stext1)+2 ; // look for initial 'equals quote' ... notice that quotes escape quotes
    sTemp = SubStr(stext1,start) ; // now save the rest beyond that point.

    end = strpos(&quot;&quot;&quot&quot;,sTemp)-1 ; // look for ending 'quote parenthesis'
    end = strpos('&quot',sTemp)-1 ; // this line is identical to the above but using a single quote wrapper
    Print(substr(stext1,start,end)) ; // now show what's left

    // Demonstrate adjustments to original attempt. It's quite hard to read but functional.
    Print(substr(stext1, strpos(&quot;=&quot;,stext1)+2, strpos('&quot', substr(stext1, strpos(&quot;=&quot;,stext1)+2))-1)) ; // single quote
    Print(substr(stext2, strpos(&quot;=&quot;,stext2)+2, strpos(&quot;&quot;&quot&quot;, substr(stext2, strpos(&quot;=&quot;,stext2)+2))-1)) ; // dbl quote
    }</pre><hr /></blockquote><font size="2" face="Verdana, Arial, Helvetica">John

  3. #3
    Member
    Join Date
    Jul 2000
    Location
    sanjose,CA,USA
    Posts
    68
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Searching for a specific text

    Hi John,
    I followed your example and resolved the issue,
    iBegin = StrPos("=", sText)+2
    iEnd = StrPos(")",sText])-1
    iLength =iEnd-iBegin
    sResult = SubStr (sText, iBegin, iLength)
    Thank you very much
    Sri

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

vBulletin Optimisation provided by vB Optimise v2.6.0 Beta 4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.0.9 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Questions / Answers Form provided by vBAnswers (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominatevBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 09:27 AM.

Copyright BetaSoft Inc.