Hi,
I want to encode input text into html format such as replace "<" with "<",
replace "&" with "&".
Could you give me some ideas? Thanks.
Fred 10 2913
Fred Yu writes:
Hi,
I want to encode input text into html format such as replace "<" with "<",
That's "<".
replace "&" with "&".
That's "&".
Could you give me some ideas? Thanks.
Try to do your homework assignment by yourself. This is a simple
search/replace operation, and there are many ways to get it done.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
iEYEABECAAYFAkhC4aQACgkQx9p3GYHlUOJbHQCdFkadJpXTIS tsphfd9cZ1yjhc
4QwAniVg+D//DKToDNz651FJF5MCYIlo
=xhO4
-----END PGP SIGNATURE-----
Fred Yu wrote:
Hi,
I want to encode input text into html format such as replace "<" with
"<", replace "&" with "&".
Could you give me some ideas? Thanks.
Containers: std::map< char, std::string >
Iterators: std::istream_iterator, std::ostream_iterator
Algorithms: std::transform
Best
Kai-Uwe Bux
On Jun 1, 12:37*pm, "Fred Yu" <jean_y_f...@sohu.comwrote:
Hi,
I want to encode input text into html format such as replace "<" with "<",
replace "&" with "&".
Could you give me some ideas? Thanks.
Fred
google iconv. It will convert from many char encodings to many other
char
encodings. I've used it to "format" text in various XML wrapper
classes.
"Fred Yu" <je*********@sohu.comschrieb im Newsbeitrag
news:g1**********@news.cn99.com...
Hi,
I want to encode input text into html format such as replace "<" with
"<",
replace "&" with "&".
Example for AnsiString Class
AnsiString Input; //contains the html code
int pos;
do // replace "<" to "<"
{
if(Input.Pos("<") NULL)
{
pos = Input.Pos("<");
Input.Delete(pos,1);
Input.Insert("%26lt",pos);
}
}
while(Input.Pos("<") NULL);
On Jun 1, 8:11 pm, Kai-Uwe Bux <jkherci...@gmx.netwrote:
Fred Yu wrote:
I want to encode input text into html format such as replace "<" with
"<", replace "&" with "&".
Could you give me some ideas? Thanks.
Containers: std::map< char, std::string >
Iterators: std::istream_iterator, std::ostream_iterator
Algorithms: std::transform
Agreed for the first (although it may be overkill---in this
particular case, I think I'd go with a simple switch).
No real need for the second; just use istream::get() and
ostream::put() (or operator<< in some cases).
As to the third: how? You're replacing a single character with
a sequence of characters, and transform does a one to one (which
in practice makes it of fairly limited utility---although I've
used it with a vector<string>, ostream_iterator, and as string
transformer class that I've written, which works something like
$(patsubst...) in GNU make).
--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
James Kanze wrote:
On Jun 1, 8:11 pm, Kai-Uwe Bux <jkherci...@gmx.netwrote:
>Fred Yu wrote:
I want to encode input text into html format such as replace "<" with
"<", replace "&" with "&".
Could you give me some ideas? Thanks.
>Containers: std::map< char, std::string > Iterators: std::istream_iterator, std::ostream_iterator Algorithms: std::transform
Agreed for the first (although it may be overkill---in this
particular case, I think I'd go with a simple switch).
No real need for the second; just use istream::get() and
ostream::put() (or operator<< in some cases).
As to the third: how? You're replacing a single character with
a sequence of characters, and transform does a one to one (which
in practice makes it of fairly limited utility---although I've
used it with a vector<string>, ostream_iterator, and as string
transformer class that I've written, which works something like
$(patsubst...) in GNU make).
I was thinking of something like this:
#include <iostream>
#include <iterator>
#include <map>
#include <algorithm>
#include <cassert>
struct encoder {
std::map< char, std::string the_map;
encoder ( void ) {
the_map[ 'a' ] = "a";
// ...
the_map[ '&' ] = "&";
// ...
}
std::string const & operator() ( char ch ) const {
std::map< char, std::string >::const_iterator iter =
the_map.find( ch );
assert( iter != the_map.end() );
return ( iter->second );
}
};
int main ( void ) {
encoder the_encoder;
std::transform( std::istreambuf_iterator<char>( std::cin ),
std::istreambuf_iterator<char>(),
std::ostream_iterator<std::string>( std::cout, "" ),
the_encoder );
}
Best
Kai-Uwe Bux
Hi!
James Kanze schrieb:
As to the third: how? You're replacing a single character with
a sequence of characters, and transform does a one to one (which
in practice makes it of fairly limited utility---although I've
used it with a vector<string>, ostream_iterator, and as string
transformer class that I've written, which works something like
$(patsubst...) in GNU make).
The source range of transform may have another value type than the
destination range.
char const* replace(char);
transform(str.begin(), str.end(),
ostream_iterator<const char*>(cout),
&replace);
Frank
On Jun 1, 11:25 pm, Frank Birbacher <bloodymir.c...@gmx.netwrote:
James Kanze schrieb:
As to the third: how? You're replacing a single character with
a sequence of characters, and transform does a one to one (which
in practice makes it of fairly limited utility---although I've
used it with a vector<string>, ostream_iterator, and as string
transformer class that I've written, which works something like
$(patsubst...) in GNU make).
The source range of transform may have another value type than the
destination range.
I'm aware of that, however...
char const* replace(char);
transform(str.begin(), str.end(),
ostream_iterator<const char*>(cout),
&replace);
For some reason, I was thinking in terms of std::string, and not
char const*. And converting each std::string seemed a bit heavy
for the task at hand. But a statically generated char const*[];
why not?
--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Hi!
James Kanze schrieb:
>char const* replace(char);
>transform(str.begin(), str.end(), ostream_iterator<const char*>(cout), &replace);
For some reason, I was thinking in terms of std::string, and not
char const*. And converting each std::string seemed a bit heavy
for the task at hand. But a statically generated char const*[];
why not?
Yes. I think I needed such a conversion once and used a switch. The
obvious problem is to efficiently handle a char that is not transformed
to more than one char (the common case). I think I actually used
for_each instead of transform:
void appendReplacement(ostream& stream, const char c)
{
switch(c)
{
case '<': stream << "<"; break;
default: stream << c; break;
}
}
This makes it possible to append different types (char or char*) to the
stream and yet requires no [CHAR_MAX] array, but lets the compiler
choose the most efficient lookup (through the switch).
Of course can this function be implemented as a functor.
Frank
"Fred Yu" <je*********@sohu.comдÈëÏûÏ¢ÐÂÎÅ:g1**********@new s.cn99.com...
Hi,
I want to encode input text into html format such as replace "<" with
"<",
replace "&" with "&".
Could you give me some ideas? Thanks.
Fred
Thanks for your help. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: francescomoi |
last post by:
Hi.
I'm trying to store a text within a MySQL field (v 3.23.58) by using
MySQLdb
(v 1.2.1c3).
The text is: "telephone..." (note the last character)
And I get this error message:...
|
by: user |
last post by:
hi there
has anyone of you writte a function to encode html from like '&' ->
'&' and likes to share it with me.. or can anybody give me a hint
how to set up something like that.
cheers me.
...
|
by: Scott Matthews |
last post by:
I've recently come upon an odd Javascript (and/or browser) behavior,
and after hunting around the Web I still can't seem to find an answer.
Specifically, I have noticed that the Javascript...
|
by: Newbie |
last post by:
How would I modify this form
to encode *all* the characters
in the 'source' textarea to the
'%xx' format & place result
code into the 'output' textarea?
(cross browser compatable)
Any help is...
|
by: ViperDK |
last post by:
What is the best way for that?
I store all Data in the original form in the Database. To prevent output
fields (especially the fields everyone can use) to do bad things like
killing the...
| |
by: Darrel |
last post by:
How does HTML.encode work?
I'm trying to save text in a hidden form field into a SQL DB. The tedt is
HTML (from a WYSIWYG editor...X-standard).
One problem I have is that stray apostrophe's in...
|
by: jtfaulk |
last post by:
I need to encode some information on the server side using ASP.NET with
C#; sending via HTTP to a client side application, that needs to be
decoded in an MFC C++ application.
I'm not sure if I...
|
by: younus |
last post by:
Hi Guys
I need some help
i want to encode arabic text to UCS2 format in asp
my text بيسليسلسيس is converted to 0633062C064A06440643002006280646062C0627 this format
plese help me this is very...
|
by: younus |
last post by:
Hi Guys
I need some help
i want to encode arabic text to UCS2 format in asp
my text بيسليسلسيس is converted to 0633062C064A06440643002006280646062C0627 this format
plese help me this is very...
|
by: Fred Yu |
last post by:
Hi,
I want to encode input text into html format such as replace "<" with "<",
replace "&" with "&".
Could you give me some ideas? Thanks.
Fred
|
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...
| |
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,...
|
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: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |