无类型1
来源:互联网 发布:ubuntu配置anaconda3 编辑:程序博客网 时间:2024/05/15 19:07
//解决思路
//可能涉及到的问题
//1:如何判断一个字符串是数字还是别的类型.
//2:如何查找一个字符串中某个符号出现的次数.
//3:如何设置EDIT光标的位置.
//1 问题的解决方法可以利用下面的方法解决.
//CString strtemp = szTemp.SpanIncluding("0123456789");
//if (!strtemp.IsEmpty())
//这个字符串为数字
//else
//非数字
//2 问题我用循环递归的方法实现,首先查找最先出现的符号位置,然后利用字符串分割技术取RIGHT部分再进 行循环调用就可以了,相关代码可以见下:
int CSampleDlg::GetStringNum(CString szVal) //获得字符串中间.号的个数
{
int nNum = 0;
while (1)
{
int nCount = szVal.Find('.');
if (nCount == - 1)
break;
szVal = szVal.Right(szVal.GetLength() - nCount - 1);
nNum++;
}
return nNum;
}
//3 问题可以采用获得EDIT控件句柄发送EM_SETSEL消息的方法实现.
//所以基本代码可以实现见下了:
void CSampleDlg::OnChange()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CEdit::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
int nPoint = 0;
CString m_estr, szTemp;
GetWindowText(m_estr);
int nLen = m_estr.GetLength();
if (!m_estr.IsEmpty())
{
szTemp = m_estr.Right(1);
BOOL bNum = TRUE;
CString strtemp = szTemp.SpanIncluding("0123456789");
if (!strtemp.IsEmpty())
bNum = TRUE;
else
bNum = FALSE;
nPoint = GetStringNum(m_estr);
if (strcmp(szTemp, ".") == 0 || bNum)
{
if (nPoint > 1)
{
nPoint--;
::AfxMessageBox(".号出现次数超过两次!");
m_estr = m_estr.Left(m_estr.GetLength() - 1);
SetWindowText(m_estr);
nLen--;
SendMessage(EM_SETSEL, nLen, nLen);
return ;
}
}
else
{
::AfxMessageBox("输入格式错误");
m_estr = m_estr.Left(m_estr.GetLength() - 1);
SetWindowText(m_estr);
nLen--;
SendMessage(EM_SETSEL, nLen, nLen);
return ;
}
}
}
- 无类型1
- 无类型与无类型指针
- 无类型文件Demo
- void 无类型
- 带符号类型和无符号类型
- 有符号类型和无符号类型
- 无符号类型的误导
- 不允许声明无类型的***
- java不存在无符号类型
- c++ void*无类型指针
- 无类型数据排序实现
- C语言--无类型指针
- ActionScript 中的无类型变量
- 判断类型是无符号类型还是有符号类型
- 对象本无根,类型亦无形
- 水晶报表无打印机,自定义纸张类型
- delphi中无类型文件读写
- 对无符号类型的建议
- 后代与房子
- 大小端模式判断
- CWF框架之公共服务-文档服务接口
- (转)vmstat结果内容的解释
- CWF框架之公共服务-全局session上下文对象
- 无类型1
- EL表达式
- Java连接搜藏
- Linux中patch文件的使用
- jedit使用指南
- 讀url 后面的參數部份
- Unix安装
- Google工程师解析Android系统架构
- BSD net源码分析(4)──环回接口