CString截取字符串全攻略函数在⽐较时不区分⼤⼩写
参数:  为要和对象⽐较的字符串,也可以为CString对象
返回值:如果两个字符串⼀样则返回0;
int strcmp( const char *string1, const char *string2 );
注:
函数在⽐较时区分⼤⼩写
参数:  为要和对象⽐较的字符串
返回值:string1=string2返回0
string1>string2返回>0
string1<string2返回<0
VC++  MFC中两CString字符串不能直接进⾏⽐较,需要转换成char*类型来进⾏⽐较。
CString  a;
CString  b;
char *pa = (char*)((LPCTSTR)a);
char *pb = (char*)((LPCTSTR)b);
if(!strcmp(pa,pb))
{
MessageBox("pa==pb");
}
最近⽤到了这⽅⾯的东西,于是把⽹上所查到的总结了⼀下,以备查询之⽤ ^_^
例程1:(csdn)
⽂件xxxx.dll去掉后⾯的.dll
⽅法1、
char str[] = "xxxx.dll"
char*p;
p=strrchr(str, '.');
*p = 0;
⽅法2、
CString str="xxxx.dll";
int n = str.ReverseFind('.')
str = str.Left(str.GetLength()-n-1);
例程2:(csdn)
取得⼀个字符串中第⼀个 '?'号之前的字符
⽅法1
CString m_char,m_disp;
m_disp="jadfueiuajdf?";
m_char="?";
if (!m_char.IsEmpty())
{
int index = m_disp.Find(m_char);
m_disp = m_disp.Right(m_disp.GetLength()-index-1);
}
返回m_disp就⾏
⽅法2cstring转为int
CString temp=the.m_bb;
CString reslut=temp.Left(temp.Find("?")-1);
例程3:(csdn)
⼀个CString类对象m_StrReceiveModem={ATS0=2
OK
$03#}
如何截取从$开始的字符串
⽅法1
CString m_StrReceiveModem;
int nPos = m_StrReceiveModem.Find('$');
if(nPos >= 0)
{
CString sSubStr = m_StrReceiveModem.Mid(nPos);//包含$,不想包含时nPos+1
}
⽅法2
CString m_StrReceiveModem;
int nPos = m_StrReceiveModem.Find('$');
if(nPos >= 0)
{
CString sSubStr = m_StrReceiveModem.Right(StrReceiveModem.GetLength()-nPos);
}
}
Split 函数
返回基于 0 的⼀维数组,其中包含指定数⽬的⼦字符串。
Split(expression[, delimiter[, count[, start]]])
参数
expression
必选项。字符串表达式,包含⼦字符串和分隔符。如果 expression 为零长度字符串,Split 返回空数组,即不包含元素和数据的数组。
delimiter
可选项。⽤于标识⼦字符串界限的字符。如果省略,使⽤空格 ("") 作为分隔符。如果 delimiter 为零长度字符串,则返回包含整个 expression 字符串的单元素数组。
count
可选项。被返回的⼦字符串数⽬,-1 指⽰返回所有⼦字符串。
Compare
可选项。指⽰在计算⼦字符串时使⽤的⽐较类型的数值。有关数值,请参阅“设置”部分。
设置
compare 参数可以有以下值:
常数值描述
vbBinaryCompare 0 执⾏⼆进制⽐较。
vbTextCompare 1 执⾏⽂本⽐较。
说明
下⾯的⽰例利⽤ Split 函数从字符串中返回数组。函数对分界符进⾏⽂本⽐较,返回所有的⼦字符串。
Dim MyString, MyArray, Msg
MyString = "VBScriptXisXfun!"
MyArray = Split(MyString, "x", -1, 1)
' MyArray(0) contains "VBScript".
' MyArray(1) contains "is".
' MyArray(2) contains "fun!".
Msg = MyArray(0) & " " & MyArray(1)
Msg = Msg & " " & MyArray(2)
MsgBox Msg
//////////////////////////////////
CString temp=the.m_bb;
CString reslut=temp.Left(temp.Find("A")-1);

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。