PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
VS 2008 [RESOLVED] How to show the word between some words?-VBForums
Results 1 to 19 of 19

Thread: [RESOLVED] How to show the word between some words?

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2009
    Posts
    37

    Resolved [RESOLVED] How to show the word between some words?

    Hello,
    How to show the word between some words?

    Like:

    <the word="Apple">

    then show: Apple

    Thank you!
    Last edited by leon100243; Nov 6th, 2009 at 08:27 AM. Reason: not resolve yet

  2. #2
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,966

    Re: How to show the word between some words?

    Hey,

    Can you provide some more information as to what exactly you are trying to do?

    Do you know ahead of time what the word will be? i.e. can you search the string for a particular word, or are you looking specifically for anything between the "'s?

    If it is the latter, then a regular expression would do the trick.

    You will find numerous examples on this forum if you do a search.

    Gary

  3. #3
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,834

    Re: How to show the word between some words?

    Quote Originally Posted by gep13 View Post
    Hey,

    Can you provide some more information as to what exactly you are trying to do?

    Do you know ahead of time what the word will be? i.e. can you search the string for a particular word, or are you looking specifically for anything between the "'s?

    If it is the latter, then a regular expression would do the trick.

    You will find numerous examples on this forum if you do a search.

    Gary

    If it is the case. Then this pattern will work

    <the word=\"(.*?)\">
    Last edited by danasegarane; Nov 4th, 2009 at 08:27 AM.
    Please mark you thread resolved using the Thread Tools as shown



    www.techreceipe.tk


  4. #4
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,966

    Re: How to show the word between some words?

    Dana, for some reason you Regex isn't appearing in your post.

    You might want to wrap it in code tags.

    Gary

    EDIT: In fact, I could see it when I tried to quote your post. Here it is:

    Code:
    <the word=\"(.*?)\">

  5. #5

    Thread Starter
    Member
    Join Date
    Apr 2009
    Posts
    37

    Red face Re: How to show the word between some words?

    I want to find those words between correct=" and " from XML like this:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    </question>
       <question sound="e-q03.mp3" viewable="true" type="fillin" text="How are the origins of the festival described? Quote your answer from the passage:" score="1">
        <set>
         <text text="• “" />
         <text correct="Apple" />
         <text text="”" />
        </set>
        <explanation text="This is a reference question. Refer to paragraph 3: “The origins of the festival are mysterious.”" />
       </question>

  6. #6
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,966

    Re: How to show the word between some words?

    Hey,

    Ah, ok, so now the picture becomes a little bit more clear.

    What do you need to do with this information? The answer to this will determine the suggested approach that you take.

    For instance, you could go down the route of a Regular Expression, as previously suggested, or you could construct an XPath query to get the information. This approach would make more sense if you need to use some of the extras node's in the XML file at the same time.

    Can you list the requirements for exactly what you are trying to do?

    Gary

  7. #7

    Thread Starter
    Member
    Join Date
    Apr 2009
    Posts
    37

    Re: How to show the word between some words?


  8. #8
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,966

    Re: How to show the word between some words?

    Hey,

    You could do this using some the following:

    Code:
            Dim xmlDoc As New XmlDocument()
            xmlDoc.Load("XmlFile1.xml")
    
            Dim correctNodes As XmlNodeList = xmlDoc.SelectNodes("/questions/question/set/text[@correct]")
    
            For Each correctNode As XmlNode In correctNodes
                ListBox1.Items.Add(correctNode.Attributes("correct").Value)
            Next
    Here I have made the following assumptions...

    1) Your xml file is in the same directory as the executable, and is called XmlFile1.xml
    2) The format of your XML file is this:

    Code:
    <?xml version="1.0" encoding="utf-8" ?>
    <questions>
    <question sound="e-q03.mp3" viewable="true" type="fillin" text="How are the origins of the festival described? Quote your answer from the passage:" score="1">
      <set>
        <text text="• “" />
        <text correct="Apple" />
        <text text="”" />
      </set>
      <explanation text="This is a reference question. Refer to paragraph 3: “The origins of the festival are mysterious.”" />
    </question>
    <question sound="e-q03.mp3" viewable="true" type="fillin" text="How are the origins of the festival described? Quote your answer from the passage:" score="1">
      <set>
        <text text="• “" />
        <text correct="Pear" />
        <text text="”" />
      </set>
      <explanation text="This is a reference question. Refer to paragraph 3: “The origins of the festival are mysterious.”" />
    </question>
    </questions>
    Note the addition of the <questions> node.

    Hope that helps!

    Gary

  9. #9

    Thread Starter
    Member
    Join Date
    Apr 2009
    Posts
    37

    Re: How to show the word between some words?

    Thank for your help ^^!
    It works~

  10. #10

    Thread Starter
    Member
    Join Date
    Apr 2009
    Posts
    37

    Re: How to show the word between some words?

    but if the format is this:
    Code:
    <?xml version="1.0" encoding="utf-8" ?>
    <questions>
    <question sound="e-q03.mp3" viewable="true" type="fillin" text="How are the origins of the festival described? Quote your answer 
    
    from the passage:" score="1">
      <set>
        <text text="• “" />
        <text correct="Apple" />
        <text text="”" />
      </set>
      <explanation text="This is a reference question. Refer to paragraph 3: “The origins of the festival are mysterious.”" />
    </question>
       <question sound="r-q01.mp3" viewable="true" type="smc" text="What was Nowruz?" correct="N">
        <answer text="It is a festival where people exchange gifts." />
        <answer text="It is a festival that celebrates the sun." />
        <answer text="It is a festival to celebrate Islam." />
        <answer text="It is a festival to celebrate the rebirth of nature." />
        <explanation text="It was a spring festival to celebrate the rebirth of nature." />
       </question>
    </questions>
    How to do it^^? Thank.

  11. #11
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,966

    Re: How to show the word between some words?

    Hey,

    What would you expect the above to return?

    I would expect it only to return Apple, since there is only one text node with a "correct" attribute?!?!

    You need to write down your exact requirements. Then I will be able to help.

    Gary

  12. #12
    Hyperactive Member
    Join Date
    May 2008
    Location
    >> ( ҉ )
    Posts
    413

    Re: How to show the word between some words?

    Quote Originally Posted by leon100243 View Post
    Hello,
    How to show the word between some words?

    Like:

    <the word="Apple">

    then show: Apple

    Thank you!
    Here you go. Code:
    1. Imports System.Text.RegularExpressions.Regex
    2. Imports System.Net
    3. Public Class Form1
    4.  
    5.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    6.         Dim WC As New WebClient
    7.         Dim DL As String = WC.DownloadString("http://127.0.0.1/File.txt")
    8.         Dim RX As New System.Text.RegularExpressions.Regex("(?<=<the word="").+?(?="">)")
    9.         MsgBox(RX.Match(DL).Value)
    10.     End Sub
    11. End Class

  13. #13
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,966

    Re: How to show the word between some words?

    Hey leon100243,

    Did you see my post?

    If you provide some more information then I am sure we can get this resolved for you, or do you already have it working?

    If so, remember to mark your thread as resolved.

    Gary

  14. #14

    Thread Starter
    Member
    Join Date
    Apr 2009
    Posts
    37

    Re: How to show the word between some words?

    Hello, I am busy last night^^
    Just:
    Download XML
    and just list all the words between correct=""s

    Like:
    Apple
    Pear
    3
    2
    4
    Orange
    (It must be sequence)

    Thank a lot^^

  15. #15
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,966

    Re: How to show the word between some words?

    Hey,

    I am happy to help out, but I would also like to see some effort on your part. What have you tried, based on what you have seen in this thread?

    In that xml, you have:

    Code:
    <text correct="XEctiAK" />
    And also you have:

    Code:
    <question sound="r-q01.mp3" viewable="true" type="smc" text="What was Nowruz?" correct="N">
    Are you saying that you want both of these?

    If so, this is a simple modification to the example that I gave you earlier.

    Gary

  16. #16

    Thread Starter
    Member
    Join Date
    Apr 2009
    Posts
    37

    Re: How to show the word between some words?

    Thank a lot^^ I will try it out~

  17. #17
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,966

    Re: [RESOLVED] How to show the word between some words?

    Hey,

    I see you have marked your thread as resolved.

    Does that mean that you have got it working? Only your last post doesn't say whether you did or not.

    Hopefully you have

    Gary

  18. #18

    Thread Starter
    Member
    Join Date
    Apr 2009
    Posts
    37

    Cool How to show the word between some words?

    I will upload my work after I finish it!!
    Thank very much

  19. #19
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,966

    Re: [RESOLVED] How to show the word between some words?

    Hey,

    Okay, sounds like a plan.

    Gary

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width