Hello again,
I am still working on this homework assignment and have hit a wall.
I have a list that I want to fill with all occurences of img tags from a
big string of html code. So I have a string called str which holds the
html code and I want to find the string str1 which would be <img and
then write to the list an item that contains all the chars from <img
through the > that closes the img tag.
I was thinking that I would use str.find(str1) in this case, but I am
not completely sure of the syntax, and how to apply it to this
situation. I don't have any code to post, because I really am stuck at
the beginning of this part.
Just a reminder, this is a homework assignment, so I would prefer
answers that help point me in the right direction rather than just the
code to use.
Thanks again
--
KL 4 4675
KL wrote: I have a list that I want to fill with all occurences of img tags from a big string of html code. So I have a string called str which holds the html code and I want to find the string str1 which would be <img and then write to the list an item that contains all the chars from <img through the > that closes the img tag.
Are you sure you're not going to find those inside, say, comments?
I was thinking that I would use str.find(str1) in this case, but I am not completely sure of the syntax, and how to apply it to this situation. I don't have any code to post, because I really am stuck at the beginning of this part.
What you're asking is not a simple thing. In many cases the html text
is a hierarchical data set, which needs to be put in a special form to
be understood. For example, if I write "<img" inside a "<pre>" segment,
finding it is not going to do any good, is it?
Of course, for a simple page you can assume that there are no nested
tags. In that case RTFM about 'find', it returns an index, IIRC. You
need to check if it's equal to 'std::string::npos', which means the
string was not found. Also pay attention that there are several 'find'
variations. You can supply the starting position from which to search.
For example, to find a matching pair of two strings you find the first
using 'find', and then find the second _starting_ from the position of
the first one (if it has been found, of course).
Just a reminder, this is a homework assignment, so I would prefer answers that help point me in the right direction rather than just the code to use.
BTW, what book are you reading that doesn't give examples of using the
'std::string' class? I strongly recommend "The C++ Standard Library"
by Josuttis.
V
--
Please remove capital As from my address when replying by mail
KL wrote: Hello again,
I was thinking that I would use str.find(str1) in this case, but I am not completely sure of the syntax, and how to apply it to this situation. I don't have any code to post, because I really am stuck at the beginning of this part.
What syntax are unsure of? Syntax of find or syntax of your string?
If former, read out the STL documentatation. Just a reminder, this is a homework assignment, so I would prefer answers that help point me in the right direction rather than just the code to use.
Try using substr. Thanks again
No problem.
on 3/4/2006 10:27 AM Victor Bazarov said the following: KL wrote:
I have a list that I want to fill with all occurences of img tags from a big string of html code. So I have a string called str which holds the html code and I want to find the string str1 which would be <img and then write to the list an item that contains all the chars from <img through the > that closes the img tag.
Are you sure you're not going to find those inside, say, comments?
It really won't matter for this particular assignment. I have already
taken the html code and saved it into one long string.
I was thinking that I would use str.find(str1) in this case, but I am not completely sure of the syntax, and how to apply it to this situation. I don't have any code to post, because I really am stuck at the beginning of this part.
What you're asking is not a simple thing. In many cases the html text is a hierarchical data set, which needs to be put in a special form to be understood. For example, if I write "<img" inside a "<pre>" segment, finding it is not going to do any good, is it?
We just need to creat a STL container that holds all the img tags. So
anything that starts <img through the closing > Of course, for a simple page you can assume that there are no nested tags. In that case RTFM about 'find', it returns an index, IIRC. You need to check if it's equal to 'std::string::npos', which means the string was not found. Also pay attention that there are several 'find' variations. You can supply the starting position from which to search. For example, to find a matching pair of two strings you find the first using 'find', and then find the second _starting_ from the position of the first one (if it has been found, of course).
So if my thinking is right (and that isn't always the case),
str.find(str1) will return the position where the first case of str1
occurs in str. I could then use a while loop to write each char into
another_string until I find the closing > tag. Then
push_back(another_string) into my list.
Now I am not clear on how to continue doing a find for the successive
cases of str1. Perhaps you could clarify that a bit more for me?
Just a reminder, this is a homework assignment, so I would prefer answers that help point me in the right direction rather than just the code to use.
BTW, what book are you reading that doesn't give examples of using the 'std::string' class? I strongly recommend "The C++ Standard Library" by Josuttis.
The book I am using is Walter Savitch's Problem Solving with C++. I
find it to be quite helpful, and it does have examples of using the
'std::string' class, I just am a bit confused in exactly how to apply
what it says and demonstrates.
--
KL V
KL skrev: on 3/4/2006 10:27 AM Victor Bazarov said the following: KL wrote:
<snip> So if my thinking is right (and that isn't always the case), str.find(str1) will return the position where the first case of str1 occurs in str. I could then use a while loop to write each char into another_string until I find the closing > tag. Then push_back(another_string) into my list.
Now I am not clear on how to continue doing a find for the successive cases of str1. Perhaps you could clarify that a bit more for me?
There are several overloaded alternatives of find(), of which one is:
find (const basic_string& str, size_type pos = 0) const;
Searches for the first occurrence of the substring specified by str in
this string, starting at position pos. If found, it returns the index
of the first character of the matching substring. If not found, returns
npos. Equality is defined by traits::eq().
<snip>
--
TB @ SWEDEN This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Peter Hansen |
last post by:
Greetings.
Im trying to write a program that can be run from the command line.
If I want to search for example after a file with the ending .pdf, I should
be able to write in the command line:...
|
by: rbt |
last post by:
Would a Python process consume more memory on a PC with lots of memory?
For example, say I have the same Python script running on two WinXP
computers that both have Python 2.4.0. One computer has...
|
by: Nils O. Selåsdal |
last post by:
Is there some quick C++ way I can do something similar to string::find ,
but case insensitive ?
|
by: Rich |
last post by:
Hello,
If my datagrid is based on a dataTable (t1) and the
currency manager is also bound to t1 and I do a find on a
key
dim dRow As DataRow, t1 As DataTable
....
dRow = t1.Rows.find(somekey)...
|
by: Jeff |
last post by:
I've been working on an application for a while now that has been giving
me some trouble when it comes to working with a picturebox and memory
usage. My company deals with digital imaging, so we...
|
by: Michael Moreno |
last post by:
Hello,
I have a C# server which has 4 worker threads running all the time.
When I let the server runs for several hours, for some reasons the CPU
usage of the application will shoot to 100% and...
|
by: rdemyan via AccessMonster.com |
last post by:
My app contains utility meter usage. One of the things we have to deal with
is when a usage is clearly incorrect. Perhaps someone wrote the meter
reading down incorrectly or made a factor of 10...
|
by: Tim Kelley |
last post by:
I am new to Visual C++ and I am having difficulty parsing a string. We have
a database that has a text field that contains multiple lines (seperated by
a carriage return and new line characters). ...
|
by: jld |
last post by:
Hi,
I developed an asp.net based eCommerce Website for a client and it is
hosted at discount asp.
The site is quite interactive, queries a database a lot and uses
ajax.asp.net to spice up...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: erikbower65 |
last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA:
1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
|
by: kcodez |
last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: Taofi |
last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same
This are my field names
ID, Budgeted, Actual, Status and Differences
...
|
by: DJRhino1175 |
last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this -
If...
|
by: Rina0 |
last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: lllomh |
last post by:
How does React native implement an English player?
| |