使用variable.Trim删除最后键入的字符 [英] Using variable.Trim to erase last character typed

查看:74
本文介绍了使用variable.Trim删除最后键入的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不记得如何修剪使用Trim函数键入的最后一个字符,我认为我需要使用var.TrimRight(??????).谁能刷新我的记忆?

谢谢,
-DrB

I can''t remember how to trim the last character typed using Trim function, I think using var.TrimRight(??????) is what I need. Can anyone refresh my memory?

Thanks,
-DrB

推荐答案

您的解决方案3表示您正在使用CString对象.因此,您可以:
Your solution 3 indicates that you are using a CString object. So you may:
// remove last character
int nLen = tempDesc.GetLength();
if (nLen)
    tempDesc = tempDesc.Left(nLen - 1);

// trim to max. length
int nLen = tempDesc.GetLength();
if (nLen > nMaxLen)
    tempDesc = tempDesc.Left(nMaxLen);


(我在这里没有VS,所以我无法检查具体细节)

2件事:

-如果要限制编辑框中的字符数,可以在资源编辑器(我认为)中或通过DDX机制进行设置.

-如果您不想限制编辑框中的字符数,只需处理几条消息并在按索引找到索引55处的字符后调用CString :: TrimRight.

M.
(I don''t have VS around here, so I cannot check the specifics)

2 things:

- If you want to limit the number of characters in your editbox, you can set it in the resource editor (I think) or via the DDX mechanism.

- If you do not want to limit the number of characters in the editbox, just handle the few messages and call CString::TrimRight after finding by index the character at the index 55.

M.


首先,最好使用内存刷新器: [ ^ ].

但是,您所需要的并不是精确的修剪(方法"Trim"是Delphi,而.NET用于删除某些字符集中的前导和/或尾随字符,默认情况下为空白字符;这不是您想要的).

如果这是一个以空字符结尾的字符串,则可以在最后一个字符的位置写一个空字符.

使用std::string,只需使用resize将当前大小减小1,请参见 http://www. cplusplus.com/reference/string/string/resize/ [ ^ ].

—SA
First of all, it''s the best to use a memory refresher: [^].

However, what you need is not exactly a trim (the method "Trim" is Delphi and .NET is used to remove leading and/or trailing characters from some set of characters, blank character by default; this is not what you want).

If this is a null-terminated strings, you can just write a null character at the position of a last character.

With std::string, simply use resize to reduce the current size by one, see http://www.cplusplus.com/reference/string/string/resize/[^].

—SA


这篇关于使用variable.Trim删除最后键入的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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