Name: Herpy McDerperson 2011-12-12 20:14
Alright, I don't get it....with hand-typed text, or the code from google.com, this works perfectly fine. On other websites, it gives me shit about a string subscript going out of range. The only thing I know for sure is that it occurs in this section of code, towards the end:
The function:
AAAAAAAAAAAAAAAAAAAAAAAAAH
//Set vector elements to lines from text file
//Open txt file
ifstream myFile;
myFile.open("parseme.txt");
while (getline(myFile, line))
{
text[linecount] = line;
linecount++; //count lines to set count for parsing
}
//Close txt file
myFile.close();
//FORMAT TEXT
for (int i = 0; i < linecount ; i++)
{
//Send line from vector to the parse method, set vector element to returned line
string temp = formatText(text[i]);
text[i] = temp;
cout<<text[i]<<endl;
}The function:
//Format line of text
string formatText(string line)
{
string newLine = "";
const int length = line.length();
//Format line of text to lowercase
for (int i = 0; i != length; i++)
line[i] = tolower(line[i]);
//Omit HTML tags and script tags/content
for (int i = 0; i != length; i++)
{
if (line[i] == '<')
{
tag = true;
newLine += " ";//Add spaces around tags so separate words don't get smushed together
if ( (line[i+1] == 's' && line[i+2] == 'c' && line[i+3] == 'r') || (line[i+1] == 's' && line[i+2] == 't' && line[i+3] == 'y') ) //Check for script or style tag
script = true;
}
//Copy text that isn't an html tag, script or style
else if (tag == false && script == false)
newLine += line[i];
else if (line[i] == '>')
{
tag = false;
newLine += " ";//Add spaces around tags so separate words don't get smushed together
if ( (line[i-7] == '/' && line[i-6] == 's' && line[i-5] == 'c' && line[i-4] == 'r') || (line[i-7] == '/' && line[i-6] == 's' && line[i-5] == 't' && line[i-4] == 'y') ) //Check for closing script or style tag
script = false;
}
}
return newLine;
}AAAAAAAAAAAAAAAAAAAAAAAAAH