CString TrimRight 不安全的因素

【论文+代码】ZS-N2N实现小样本零网络图像去噪 本文涵盖论文原文讲解与代码复现。 阅读详情
在用CString的时候,一直用TrimRight去掉空格,及右侧的字符,字符串,用着挺方便,一直没多考过真正含义,结果终于有一天莫名的出错了。
写一个检查程序时,想保留IAT中的API名称,但不要Ex,ExA ,这些扩展的名称,因为从API函数的含义上这些都是一个意思。
所以有如下程序,
void parse_iat_api_name(char *iat_api_name)
{
CString  strAPI = iat_api_name;    
strAPI.TrimRight("ExA");
strAPI.TrimRight("ExW");
}
乍一看代码没问题,跑了一些测试样本也没问题,但当iat_api_name = “OpenMutexA” ,有这类特点的Api 时问题来了,经过转换,strAPI变成了OpenMute, 那个‘x’ 被干掉了,按我以前的理解是,这个函数,大小写敏感的匹配右段,然后干掉右侧能匹配的字符串,可惜结果不是,下面是MFC中的实现,


void CString::TrimRight(LPCTSTR lpszTargetList)
{
// find beginning of trailing matches
// by starting at beginning (DBCS aware)


CopyBeforeWrite();
LPTSTR lpsz = m_pchData;
LPTSTR lpszLast = NULL;


while (*lpsz != '\0')
{
if (_tcschr(lpszTargetList, *lpsz) != NULL)  --- 当”OpenMutexA“递减到仅剩"xA"时,被”ExA“匹配到,
{                                                                 --- 出了问题
if (lpszLast == NULL)
lpszLast = lpsz;
}
else
lpszLast = NULL;
lpsz = _tcsinc(lpsz);  ----》 _tcsinc 相当于让lpsz 做指针加1的操作,不断从左侧递减要
处理的“OpenMutexA”
}                                             


if (lpszLast != NULL)
{
// truncate at left-most matching character
*lpszLast = '\0';
GetData()->nDataLength = lpszLast - m_pchData;
}
}
所以该函数并不是全字匹配右端函数,我理解上有误。
---------------------------------------------------------------------------------------------------------
下面给出安全的去掉右端的字符串的代码
想要去除的右侧后缀,添加ptrimstring 到表即可


bool  trim_r_string(char *string,CString &str)
{
if(!string)
return fasle;


CString str = string;
const char *ptrimstring[] = 
{
"ExA",
"ExW",
"Ex",
"A",
"W",
0
}; // 这里要注意,一定要从字符多到字符少的这个顺序.
int str_size = str.GetLength();
for(int i = 0; ptrimstring[i];i++)
{
int len = strlen(ptrimstring[i]);
if(len >= str_size)
continue;


char *pex = (LPSTR)(LPCTSTR)str;
pex += (str_size - len);


if(pex && 0 == strncmp(pex,ptrimstring[i],len))
{
strAPI = strAPI.Left(str_size - len);
break;
}        
}
return true;
} 

一本集成电路静态时序设计经典之作(可下载) 本书全面深入探讨集成电路设计中关键技术的专著,涵盖了从基础知识到高级应用的各个方面。本书详细介绍了集成电路的发展历程、**静态时序分析的重要性、基本时序模型、时序信息库文件的构建、时序约束的设置、串扰噪声的影响及其控制方法**,并通过实战案例展示了如何进行有效的时序分析和优化。 阅读详情

相关推荐

安装IC Complier 2(安装synposys的其他工具也可以来看看,因为殊途同归)

安装ICC2

hjt66666的博客 5792

CString的Trim()方法和TrimStrat()和TrimEnd()方法,TrimRight()和TrimLeft() 方法

一、 CString的Trim()方法和TrimStrat()和TrimEnd()方法。这三个方法用于删除字符串头尾出现的某些字符。 Trim()删除字符串头部及尾部出现的空格,删除的过程为从外到内,直到碰到一个非空格的字符为止,所以不管前后有多少个连续的空格都会被删除掉。 TrimStart()只删除字符串的头部的空格。 TrimEnd()只删除字符串尾部的空格。 注意:如果这三个函数...

zxf347085420的博客 5951

从实验室到生产线:Qwen3-Omni后训练技术在实际业务中的落地挑战

本文探讨了Qwen3-Omni后训练技术在实际业务中的落地挑战,重点分析了多模态AI在工业应用中的关键问题与解决方案。通过金融风控、跨境电商等场景案例,揭示了通用模型与垂直需求的矛盾,并提供了知识蒸馏、语音合成优化等实战经验,助力企业实现技术到业务的转化。

weixin_29035147的博客 272

CString的trimleft,trimright和Trim 去除空格

Trim只去除首位的空格,如果要去除全部的,用CStringT::Remove方法。 TrimLeft方法的意义是:从字符串左边看起,遇到括号中出现的字符(参数)全部截去,直到出现第一个括号中未出现的字符时停止截除,即使后面又出现了参数中有的字符也不会截去了。TrimLeft方法的意义是:从字符串左边看起,遇到括号中出现的字符(参数)全部截去,直到出现第一个括号中...

weixin_34293911的博客 1004

STM32独立实现CANOpen主机功能:从零构建轻量级控制方案

本文详细介绍了如何在STM32上不依赖CanFestival库,从零构建一个轻量级的CANOpen主机方案。文章深入剖析了CANOpen主机的三大核心功能——NMT网络管理、SDO参数配置与PDO过程数据交换,并提供了从硬件准备、驱动层构建到协议实现的完整代码实战。该方案代码精简,资源占用低,特别适合在资源受限的STM32平台上实现工业控制、电机驱动等场景的稳定通信。

potato的博客 1079

〖Python WEB 自动化测试实战篇⑤〗- selenium 元素定位详解 - (八大元素定位方式)

测试对象的定位和操作是我们利用 selenium 编写自动化脚本和 webdriver 的核心内容,其中 "操作" 这一部分又是建立在 "selenium" 元素定位的基础之上的。所以对元素对象的定位就显得越发的重要,接下来我们就学习一下常用的元素定位方法有哪些。......

易编橙 · 终身成长社群,相遇已是上上签! 4万+

CString TrimRight 的问题

1.  该函数功能并不是删除全字匹配右端参数,而是匹配从参数右端开始的部分字符 如: CString strTest; strTest = "OpenMutexA";  strTest.TrimRight("MxA"); 得到的结果是"OpenMute"。 2.  该函数不支持汉字 CString     tt   =   "我的问题"   ;  tt.TrimR

zigzagfist的专栏 1108

matlab 点云学习目录【2026最新版】

matlab 点云学习目录。博客长期更新,本文最近更新时间为:2026年6月15日。

点云侠的博客 3万+

CString::TrimLeft和CString::TrimRight

CString::TrimLeft void TrimLeft( );当在没有参数的情况下调用时,TrimLeft删除字符串最前面的换行符,空格和tab字符。 void CString::TrimLeft( TCHAR chTarget ); void CString::TrimLeft( LPCTSTR lpszTargets ); Parameters chTarget The t

Gordennizaicunzai的博客 2117

调节桌面图标大小的方法(编程)

如果你对其他操作系统或编程语言有类似的需求,可以根据具体的情况进行相应的调整和搜索相关的库和方法。在编程中,我们可以使用各种桌面应用程序来调节桌面图标的大小。库提供的函数,我们获取了桌面图标的窗口句柄,并使用Windows消息发送方式设置图标的大小。你可以根据自己的需求修改代码中的图标大小值,并在运行代码后观察桌面图标的变化。函数并传入所需的图标大小,这里设置为48x48像素。首先,我们需要使用Python的第三现的方法。首先,我们需要使用Python的第三方库。首先,我们需要使用实现的方法。

CyberFlare的博客 440

数据结构之博弈树搜索(深度优先搜索)

数据结构之博弈树搜索(深度优先搜索)

LucianaiB的博客 1532

CString中的TrimLeft()和TrimRight()的用法----对比isspace()

一个CString字符串,如果在字符串的开始或结尾有空格的时候,可以使用TrimRight()和TrimLeft()来消去空格,例如CString str="   xiesiyuan    ";CString str1;CString str2; str1=str;str.TrimLeft();str2=str;这时候我们刷新窗口,会发现str1="   xiesi

Seanyxie Blog 1万+

基于分水岭分割进行肺癌诊断

近年来,肺癌的发病率和病死率均迅速上升,目前已居所有癌症之首。随着肺癌病人数量的增加,医生对肺部 CT 图像进行研判的工作量也增加了不少,在这种情况下难免工作效率降低甚至会出现误诊。为了帮助医生减少重复性工作,对肺部 CT 图像进行计算机辅助检测的技术就被广泛应用于对肺癌的诊断和治疗过程中。医学 CT 图像处理主要是研究医学图像中的器官和组织之间的关系,并进行病理性分析。

在职AI算法工程师,擅长计算机视觉,YOLO目标检测、分割等,擅长web、pyqt界面可视化,好内容持续更新中,来这里跟大家一起学习,共同进步 1572

CString的TrimRight的使用误区

CString的TrimRight的使用误区  今天同事发现一个问题,经研究是我们的使用错误。 通常我们会把这个方法用作截掉右侧的字符串,比如,获取文件的全路径名,然后截掉文件名获得文件所在路径。但是在这里凑巧出现了错误。      CString str = _T("aaa.ini\\FileExchage\\SharEEEEEEEFileaa\\\\\\ageeExchange\\Fil

thanklife的专栏 4823

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

CString函数

CString的构造函数 CString( ); 例:CString csStr; CString( const CString& stringSrc ); 例:CString csStr("ABCDEF中文123456"); CString csStr2(csStr); CString( TCHAR ch, int...

fnjejkd的博客 1429

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

CString的Trim()方法和TrimStrat()和TrimEnd()方法

这三个方法用于删除字符串头尾出现的某些字符。Trim()删除字符串头部及尾部出现的空格,删除的过程为从外到内,直到碰到一个非空格的字符为止,所以不管前后有多少个连续的空格都会被删除掉。TrimStart()只删除字符串的头部的空格。TrimEnd()只删除字符串尾部的空格。 如果这三个函数带上字符型数组的参数,则是删除字符型数组中出现的任意字符。如Trim("abcd".ToCharArra

ghevinn欢迎您光临 2万+

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

CString中TrimLeft()与TrimRight()的用法

CString::TrimLeft void TrimLeft( ); void CString::TrimLeft( TCHAR chTarget ); void CString::TrimLeft( LPCTSTR lpszTargets ); 参数: chTarget 要被整理的目标字符。 lpszTargets 指向一个字符串的指针,该字符串包含了要被整理的目

legend的专栏 8423

CString字符串查找和截取与去空格(Find,FindOneOf,ReverseFind,Left,Mid,Right,substr,TrimLeft和TrimRight)

一、CString之Find()、FindOneOf()、ReverseFind()。 此三个函数返回值均为整数int。 1、Find() 该函数从最左侧0位置开始索引,查找到第一个出现该字符的位置,返回position。示例如下: CString s("abcabc"); ASSERT( s.Find('b') == 1 ); intf=s.Find("de")...

lzzw的学习之路 5856

c++去除cstring空格_C++ string的trim, split方法

很多其他语言的libary都会有去除string类的首尾空格的库函数,但是标准C++的库却不提供这个功能。但是C++string也提供很强大的功能,实现trim这种功能也不难。下面是几种方法:1.使用string的find_first_not_of,和find_last_not_of方法/*Filename:StringTrim1.cppCompiler:VisualC++8.0Des...

weixin_28697921的博客 945

(转贴)CString.TrimLeft() CString.TrimRight()函数用法

<br />CString str = "/n/t a";<br />str.TrimLeft();<br />str为“a”;<br />如果没有参数,从左删除字符(/n/t空格等),至到遇到一个非此类字符.<br />当然你也可以指定删除那些字符.<br />如果指定的参数是字符串,那么遇上其中的一个字符就删除.<br />CString str = "abbcadbabcadb ";<br />str.TrimLeft("ab");<br />结果"cadbabcadb "  <br /> <br /

gyjdk0601的专栏 1626

CString类常用方法----TrimLeft(),TrimRight()

void TrimLeft( );     //把字符串左边的空格去掉void TrimRight( );   //把字符串右边的空格去掉例: CString a,b; b = a = "   123456789  "; a.TrimLeft();     //得到的字符串为"123456789  " b.TrimRight();    //得到的字符串为"   1234567

轻轻浪花 3587

CString 使用

Point,Frontpage,Outlook Express,Forté Agent,Internet Explorer和其它的一些。),而在 Unicode 编码系统中编译成_wtoi()。pp,在你 vc98的安装目录的 mfc/src 子目录中。// ... 部分省略许多细节。sual Basic 的人占了上风,BSTR("Basic String"的首字母缩写)就是这场争论的结果。在 Unicode 模式中,将成为标准的 CString 构造函数,参见对缺省::WideCharTo。

phenixyf的专栏 1029

CString常用函数

CString常用函数CString::CString(char *p) {              int n=strlen(p);              m_data = new char[n+1];              strcpy(m_data,p); } CString::CString(CString &other) {              int n=str

凤凰程序员的专栏 1349

CString::trimleft()函数介绍:

1.     CString   s   =   "0x0001";     s.TrimLeft("0x1");     AfxMessageBox(s);     输出   :   空         2.     CString   s   =   "0x0001";     s.TrimLeft("0x");     AfxMessageBox(s);     输出   :   1    

lyd_253261362的专栏 8579

CString常用方法简介

CString常用方法简介 1.CString::IsEmpty BOOL IsEmpty( ) const; 返回值:如果CString 对象的长度为0,则返回非零值;否则返回0。 说明:此成员函数用来测试一个CString 对象是否是空的。 示例: 下面的例子说明了如何使用CString::IsEmpty。 // CString::IsEmpty 示例 CStri

lambition的专栏 520
上一篇: 给初学C++的者50条忠告——转自【CSND】
下一篇: U-Boot移植完毕
slshelly
博客等级 码龄19年 52粉丝 10原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值