Sign in to follow this  

meta tags how to process it

This topic is 4664 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

You mean HTML meta tags?
What scripting langauge?

I can show you how to do it in C++, assuming the tag is of the format <meta name="tagname" content="tagcontent"> it's easy:

bool ProcessMetaTag(const string& strTag, string& strName, string& strContent)
{
string strIn(strTag);

// Check it starts with "<meta"
if(stricmp(strIn.sub(0,5).c_str(),"<meta") != 0)
retrun false;
strIn.erase(strIn.begin(),strIn.begin()+5);

// Trim whitespace //
while(strIn[0] == ' ') strIn.erase(strIn.begin());

// Extract 'name="' part //
if(stricmp(strIn.sub(0,6).c_str(),"name=\"") != 0)
retrun false;
strIn.erase(strIn.begin(),strIn.begin()+6);

// Find end of tag //
int nPos = strIn.find('\"');
if(nPos == string::npos)
return false;

// Save name tag //
strName = strIn.substr(0,nPos);
strIn.erase(strIn.begin(),strIn.begin()+nPos+1);

// Trim whitespace //
while(strIn[0] == ' ') strIn.erase(strIn.begin());

// Extract 'content="' part //
if(stricmp(strIn.sub(0,9).c_str(),"content=\"") != 0)
retrun false;
strIn.erase(strIn.begin(),strIn.begin()+9);

// Find end of tag //
int nPos = strIn.find('\"');
if(nPos == string::npos)
return false;

// Save content tag and return //
strContent = strIn.substr(0,nPos);
return true;
}




That's totally off the top of my head, and isn't at all robust.

Share this post


Link to post
Share on other sites
If you're going to write this in C++ you can also use some regular expression library, like the one supplied by Boost. Unfortunately I haven't had the time yet to look into it myself.

Most scripting languages also support regular expressions. Make use of them while parsing text!

Share this post


Link to post
Share on other sites

This topic is 4664 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this