从cstring vc ++ mfc替换一些特殊字符(需要引用特殊字符) [英] Replacing some special characters from a cstring vc++ mfc(special characters need to be quoted )

查看:800
本文介绍了从cstring vc ++ mfc替换一些特殊字符(需要引用特殊字符)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有cstring,它会存储用户输入的详细信息(用户输入的详细信息)。

假设用户输入*&#(%^&((

然后我的字符串就像是

Cstring groupname;

groupname =*&#(%^&(((组名将包含用户字符)

但我想更换一些字符

假设用户输入&然后我将其替换为amp

你能建议我怎么解决这个问题。



我尝试过的事情:



我是mfc的新手,所以我不知道这里

解决方案

如果你不知道如何使用特定的类有一个首先查看文档。在这种情况下,您可能会找到 CStringT :: Replace [ ^ ]方法。



要TMLify CString s使用:

  / *  首先替换'&'。 * /  
str.Replace(_T( &), _T( & amp;));
str.Replace(_T( <),_ T( & lt;));
str.Replace(_T( >),_ T( & gt;));
str.Replace(_T( \),_ T( & quot;));

对于XML,也替换单引号字符&安培;者;


I have cstring and it will store the user input details(user entered details).
suppose user enter "*&#(%^&(("
then my string is like
Cstring groupname;
groupname = "*&#(%^&(("(group name will contain user eneter characters)
but I want to replace some characters in that
suppose if user entered as "&" then I have replace that as "amp"
could you please suggest me how to solve this.

What I have tried:

I am new to mfc so I have no idea here

解决方案

If you don't know how to do such when using a specific class have a look at the documentaion first. In this case you might find the CStringT::Replace[^] method.

To "TMLify CStrings use:

/* Replace '&' first. */
str.Replace(_T("&"), _T("&amp;"));
str.Replace(_T("<"), _T("&lt;"));
str.Replace(_T(">"), _T("&gt;"));
str.Replace(_T("\""), _T("&quot;"));

For XML replace also the single quote character with &apos;


这篇关于从cstring vc ++ mfc替换一些特殊字符(需要引用特殊字符)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆