473,387 Members | 1,455 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

stripping from string

2
First of all, ive been trying to learn c++ for a couple of days ;)

Problem i need to strip http links from string

code:

string replaceAll(string s, string f, string r) {
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, "&lt;", "<");
s = replaceAll(s, "&gt;", ">");
s = replaceAll(s, "&amp;", "&");
s = replaceAll(s, "&nbsp;", " ");
// Etc...
return s;
}


if i try to change

unsigned int left = s.find('<');

to

unsigned int left = s.find('http:');

i get this error: warning: character constant too long for its type

Which must be due to int contains one byte??
Apr 19 '08 #1
2 1898
Banfa
9,065 Expert Mod 8TB
unsigned int left = s.find('http:');

i get this error: warning: character constant too long for its type

Which must be due to int contains one byte??
More or less although I believe character constants actually have type char in C++. Single quotes indicate a character constant so you can unly have a single character between them. If you wish to us a string use double quotes

unsigned int left = s.find("http:");
Apr 19 '08 #2
ventos
2
thanks. your solution worked. script compiles now as supposed.

My approach to the problem however wasn't correct. It seems this would only work as long as the target string only had one http link in it.

Ill have to rethink my strategy ;)
Apr 19 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Margaret MacDonald | last post by:
I've been going mad trying to figure out how to do this--it should be easy! Allow the user to enter '\_sometext\_', i.e., literal backslash, underscore, some text, literal backslash, underscore...
4
by: joram gemma | last post by:
Hello, on windows python 2.4.1 I have the following problem >>> s = 'D:\\music\\D\\Daniel Lanois\\For the beauty of Wynona' >>> print s D:\music\D\Daniel Lanois\For the beauty of Wynona >>>...
7
by: Raj | last post by:
Hi I was hoping someone could suggest a simple way of stripping non-numeric data from a string of numbers. For example, if I have "ADB12458789\n" I would like to remove the letters and the...
4
by: Lu | last post by:
Hi, i am currently working on ASP.Net v1.0 and is encountering the following problem. In javascript, I'm passing in: "somepage.aspx?QSParameter=<RowID>Chèques</RowID>" as part of the query...
5
by: David Sawyer | last post by:
I am trying to read in an HTML file and strip out the HTML code so that all I have left is the text of the body. Does anyone have any suggestions for doing this? Any HTML stripping routines or...
6
by: eight02645999 | last post by:
hi wish to ask a qns on strip i wish to strip all spaces in front of a line (in text file) f = open("textfile","rU") while (1): line = f.readline().strip() if line == '': break print line
4
by: Spondishy | last post by:
Hi, I'm looking for help with a regular expression and c#. I want to remove all tags from a piece of html except the following. <a> <b> <h1> <h2>
7
by: Edward Elliott | last post by:
I'm looking for the "best" way to strip a large set of chars from a filename string (my definition of best usually means succinct and readable). I only want to allow alphanumeric chars, dashes,...
7
by: Benway | last post by:
Hey all, I have a file name like Eng-Cat-01-01-01.txt. I need to do a loop that starts stripping the letters from the front of this file name (which I'll store as a variable) until it reaches the...
4
by: Tim Cook | last post by:
Hi All, I just ran into an issue with the rstrip method when using it on path strings. When executing a function I have a need to strip off a portion of the current working directory and add...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.