Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do i get all the text from the string in a loop and not only once?
    primarykey
    data
    text
    <p>I have this code:</p> <pre><code>private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; WebRequest request = WebRequest.Create(url); request.Method = "GET"; WebResponse response = request.GetResponse(); Stream stream = response.GetResponseStream(); StreamReader reader = new StreamReader(stream); string content = reader.ReadToEnd(); reader.Close(); response.Close(); } </code></pre> <p>Now i have two functions:</p> <pre><code>private void GetProfileNames(string text) { string startTag = "&lt;a href='/profile/"; string endTag = "'&gt;"; int startTagWidth = startTag.Length; int endTagWidth = endTag.Length; index = 0; while (true) { index = text.IndexOf(startTag, index); if (index == -1) { break; } // else more to do - index now is positioned at first character of startTag int start = index + startTagWidth; index = text.IndexOf(endTag, start + 1); if (index == -1) { break; } // found the endTag profileName = text.Substring(start, index - start); } return profileName; } private void GetTextFromProfile(string text) { string str = "&lt;span class=\"message-text\"&gt;"; string startTag = str; string endTag = "&lt;"; int startTagWidth = startTag.Length; int endTagWidth = endTag.Length; index = 0; while (true) { index = text.IndexOf(startTag, index); if (index == -1) { break; } // else more to do - index now is positioned at first character of startTag int start = index + startTagWidth; index = text.IndexOf(endTag, start + 1); if (index == -1) { break; } // found the endTag profileNameText = text.Substring(start, index - start); } return profileNameText; } </code></pre> <p>Now after the string content line in the DoWork event i called the function: GetProfileNames but when im using a breakpoint on the line: profileNameText = text.Substring(start, index - start); im getting the same profile name all the time i need to close the program run it again.</p> <p>What i want it to do is when im calling the function in the Dowork event it will make the GetProFileNames function to the end and get all the profile names from the current content that have been downloaded.</p> <hr> <p>Somehow i need to call the both functions: GetProfileNames and GetTextFromProfile and i need to create a string of each profile and the text that belong to him.</p> <p>For example i have this line in the content variable:</p> <pre><code>&lt;span class="message-profile-name" &gt;&lt;a href='/profile/LipazD'&gt;LipazD&lt;/a&gt;&lt;/span&gt;: &lt;span class="message-text"&gt;hello world&lt;/span&gt; </code></pre> <p>So I need that the both functions will loop over the content and each time there was itertion i will get a string like string t = "LipazD hello world" Next itertion will be: "Daniel how are you ?"</p> <p>The functions work they get the profile name and the second one get the text but i dont know how ot make itertion loop and to get it all to work.</p> <hr> <p>Then when it finish to loop over the content and get all profile names and text for each profile name i need to delete the content and download again a new content and then do it again with the functions finished delete content or just download a new content and so on over and over again.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload