VC 中常用字符串比较和查找函数
来源:互联网 发布:里番在哪里看 知乎 编辑:程序博客网 时间:2024/05/22 03:13
1. 字符串比较函数
//比较两个字符串是否相同
int StrCmp(LPCTSTR lpStr1,LPCTSTR lpStr2);
int StrCmpN(LPCTSTR lpStr1,LPCTSTR lpStr2,int nChar);
int strcmp( const char *string1, const char *string2 );
int wcscmp( const wchar_t *string1, const wchar_t *string2 );
int CompareString(LCID Locale, DWORD dwCmpFlags, LPCTSTR lpString1, int cchCount1, LPCTSTR lpString2, int cchCount2);
size_t strlen( const char *string );
size_t wcslen( const wchar_t *string );
3. 字符串赋值函数
HRESULT StringCchCopy(LPTSTR pszDest,size_t cchDest,LPCTSTR pszSrc); //replacement for strcpy
HRESULT StringCchCopyN(LPTSTR pszDest,size_t cchDest,LPCTSTR pszSrc,size_t cchSrc); //replacement for strncpy
LPTSTR StrCpy(LPTSTR psz1,LPCTSTR psz2); //存在安全问题
LPTSTR StrCpyN(LPTSTR psz1,LPCTSTR psz2,int cchMax); //存在安全问题
char *strcpy( char *strDestination, const char *strSource );
wchar_t *wcscpy( wchar_t *strDestination, const wchar_t *strSource );
char *strncpy( char *strDest, const char *strSource, size_t count );
wchar_t *wcsncpy( wchar_t*strDest, const wchar_t *strSource, size_t count );
4. 字符串连接函数
HRESULT StringCchCat( LPTSTR pszDest,size_t cchDest,LPCTSTR pszSrc); //replacement for strcat
HRESULT StringCchCatN( LPTSTR pszDest,size_t cchDest,LPCTSTR pszSrc,size_t cchMaxAppend); //replacement for strncat
LPTSTR StrCat( LPTSTR psz1,LPCTSTR psz2); //存在安全问题
LPTSTR StrNCat( LPTSTR pszFront,LPCTSTR pszBack,int cchMax); //存在安全问题
char *strcat( char *strDestination, const char *strSource );
wchar_t *wcscat( wchar_t *strDestination, const wchar_t *strSource );
char *strncat( char *strDest, const char *strSource, size_t count );
wchar_t *wcsncat( wchar_t *strDest, const wchar_t *strSource, size_t count );
5. 字符查找函数
//查找字符串中指定字符第一次出现的位置
LPTSTR StrChr( LPCTSTR lpStart,TCHAR wMatch); //区分大小写
char *strchr( const char *string, int c );
wchar_t *wcschr( const wchar_t *string, wchar_t c );
LPTSTR StrChrI( LPCTSTR lpStart,TCHAR wMatch); //不区分大小写
//查找字符串中指定字符最后一次出现的位置
LPTSTR StrRChr( LPCTSTR lpStart,LPCTSTR lpEnd,TCHAR wMatch); //区分大小写
char *strrchr( const char*string, int c );
wchar *wcsrchr( const wchar_t *string, int c );
LPTSTR StrRChrI( LPCTSTR lpStart,LPCTSTR lpEnd,TCHAR wMatch); //不区分大小写
*注 StrRChr()函数可以通过StrChr()函数和while循环来实现。
补充:
查找字符串:
_tcsstr(........)
字符串转化为double型数字
_tcstod( const char *nptr, char **endptr )
字符串转化为double型整数(只取整数部分,不取小数)Convert strings to a long-integer value.
_tcstoul ( const char *nptr, char **endptr, int base )
_tcstol ( const char *nptr, char **endptr, int base )
取子字符串
Extracts a substring of length nCount characters from this CStringT object, starting at position iFirst (zero-based).
CStringT Mid(
int iFirst,
int nCount
) const;
CStringT Mid(
int iFirst
) const;
example:
//typedef CStringT < TCHAR, StrTraitATL < TCHAR > > CAtlString;
CAtlString s( _T("abcdef") );
_ASSERT( s.Mid( 2, 3 ) == _T("cde") );
//比较两个字符串是否相同
int StrCmp(LPCTSTR lpStr1,LPCTSTR lpStr2);
int StrCmpN(LPCTSTR lpStr1,LPCTSTR lpStr2,int nChar);
int strcmp( const char *string1, const char *string2 );
int wcscmp( const wchar_t *string1, const wchar_t *string2 );
int CompareString(LCID Locale, DWORD dwCmpFlags, LPCTSTR lpString1, int cchCount1, LPCTSTR lpString2, int cchCount2);
2. 计算字符串长度
size_t strlen( const char *string );
size_t wcslen( const wchar_t *string );
3. 字符串赋值函数
HRESULT StringCchCopy(LPTSTR pszDest,size_t cchDest,LPCTSTR pszSrc); //replacement for strcpy
HRESULT StringCchCopyN(LPTSTR pszDest,size_t cchDest,LPCTSTR pszSrc,size_t cchSrc); //replacement for strncpy
LPTSTR StrCpy(LPTSTR psz1,LPCTSTR psz2); //存在安全问题
LPTSTR StrCpyN(LPTSTR psz1,LPCTSTR psz2,int cchMax); //存在安全问题
char *strcpy( char *strDestination, const char *strSource );
wchar_t *wcscpy( wchar_t *strDestination, const wchar_t *strSource );
char *strncpy( char *strDest, const char *strSource, size_t count );
wchar_t *wcsncpy( wchar_t*strDest, const wchar_t *strSource, size_t count );
4. 字符串连接函数
HRESULT StringCchCat( LPTSTR pszDest,size_t cchDest,LPCTSTR pszSrc); //replacement for strcat
HRESULT StringCchCatN( LPTSTR pszDest,size_t cchDest,LPCTSTR pszSrc,size_t cchMaxAppend); //replacement for strncat
LPTSTR StrCat( LPTSTR psz1,LPCTSTR psz2); //存在安全问题
LPTSTR StrNCat( LPTSTR pszFront,LPCTSTR pszBack,int cchMax); //存在安全问题
char *strcat( char *strDestination, const char *strSource );
wchar_t *wcscat( wchar_t *strDestination, const wchar_t *strSource );
char *strncat( char *strDest, const char *strSource, size_t count );
wchar_t *wcsncat( wchar_t *strDest, const wchar_t *strSource, size_t count );
5. 字符查找函数
//查找字符串中指定字符第一次出现的位置
LPTSTR StrChr( LPCTSTR lpStart,TCHAR wMatch); //区分大小写
char *strchr( const char *string, int c );
wchar_t *wcschr( const wchar_t *string, wchar_t c );
LPTSTR StrChrI( LPCTSTR lpStart,TCHAR wMatch); //不区分大小写
//查找字符串中指定字符最后一次出现的位置
LPTSTR StrRChr( LPCTSTR lpStart,LPCTSTR lpEnd,TCHAR wMatch); //区分大小写
char *strrchr( const char*string, int c );
wchar *wcsrchr( const wchar_t *string, int c );
LPTSTR StrRChrI( LPCTSTR lpStart,LPCTSTR lpEnd,TCHAR wMatch); //不区分大小写
*注 StrRChr()函数可以通过StrChr()函数和while循环来实现。
补充:
查找字符串:
_tcsstr(........)
字符串转化为double型数字
_tcstod( const char *nptr, char **endptr )
字符串转化为double型整数(只取整数部分,不取小数)Convert strings to a long-integer value.
_tcstoul ( const char *nptr, char **endptr, int base )
_tcstol ( const char *nptr, char **endptr, int base )
取子字符串
Extracts a substring of length nCount characters from this CStringT object, starting at position iFirst (zero-based).
CStringT Mid(
int iFirst,
int nCount
) const;
CStringT Mid(
int iFirst
) const;
example:
//typedef CStringT < TCHAR, StrTraitATL < TCHAR > > CAtlString;
CAtlString s( _T("abcdef") );
_ASSERT( s.Mid( 2, 3 ) == _T("cde") );
转自:http://wenku.baidu.com/view/2e10bc6b7e21af45b307a85e
- VC 中常用字符串比较和查找函数
- VC 中字符串比较和查找
- VC 中字符串比较和查找
- VC 中字符串比较和查找
- VC 中字符串比较和查找
- 常用字符串查找函数
- VC常用字符串函数
- VC中支持中文的字符串比较函数
- 字符串比较函数strncasecmp():比较字符串的前n个字符|字符串查找函数strstr和string.find() 查找字符串str1中是否存在与str2一样的子字符串
- VC++ 比较字符串是否相等的函数strcmp和wcscmp
- PHP字符串比较和查找
- ColdFusion中常用几种字符串查找函数
- VC字符串转换常用函数
- VC++常用字符串转换函数
- VC字符串转换常用函数
- php中常用的字符串比较函数strcmp()实例解释
- php 字符串 函数 查找 比较 截取
- java字符串处理常用函数(数字型和字符串转换,字符串拆分、查找、截取)
- CursorAdapter的一段代码
- python使用suds来调用webservice
- NCE第一课学习
- Python_Scrapy入门教程(2)
- 程序人生--一个程序员对学弟学妹建议
- VC 中常用字符串比较和查找函数
- 浅谈程序员的数学修养(转)
- 单词串联记忆 - 故事 - Party上浪漫的事后传
- 第十二章 常用类
- java集合复习转载
- 工作学习笔记——10月
- PHP设计模式——适配器模式(研磨设计模式学习笔记)
- python 调用webservice两种方式
- 大一9月初入学至10月底总结