Strip Html Tag

Strip Html Tag

節錄至
Thinking in C++, 2nd edition, Volume 2, 4: Strings in Depth

{
	unsigned int found = s.find(f);
	while(found != string::npos) 
	{
		s.replace(found, f.length(), r);
		found = s.find(f);
	}
	return s;
}
 
string stripHTMLTags(string s) 
{
	while(true) 
	{
		unsigned int left = s.find('<');
		unsigned int right = s.find('>');
		if(left==string::npos || right==string::npos)
			break;
		s = s.erase(left, right - left + 1);
	}
	s = replaceAll(s, "<", "<");
	s = replaceAll(s, ">", ">");
	s = replaceAll(s, "&", "&");
	s = replaceAll(s, " ", " ");
	// Etc...
	return s;
}

 

Dotblogs 的標籤: ,