void to_upper(char *src, int len)
{
for(int i = 0; i < len; i++)
src[i] &= 0xDF;
}
void to_lower(char *src, int len)
{
for(int i = 0; i < len; i++)
src[i] |= 0x20;
}
11 个解决方案
#1
要不要判断一下src[i]不是字母的情况?
一般来说,对于非字母的字符(比如数字),toupper或tolower应该是保持原值不变的
一般来说,对于非字母的字符(比如数字),toupper或tolower应该是保持原值不变的
#2
不错,不过这样代码的时候应该有个注释,方便别人能理解。
我记得王爽的汇编语言里面有个这个,就是把第6位置1(大写)或置0(小写)。
#3
如果就拿src作为字符串来用,那么len未必有必要,直接用'\0'判断字符串结束即可。
#4
有道理
#5
加个len可能更灵活吧
#6
String Manipulation
These routines operate on null-terminated single-byte character, wide-character, and multibyte-character strings. Use the buffer-manipulation routines, described in Buffer Manipulation, to work with character arrays that do not end with a null character.
String-Manipulation Routines
Routine Use
_mbscoll, _mbsicoll, _mbsncoll, _mbsnicoll Compare two multibyte-character strings using multibyte code page information (_mbsicoll and _mbsnicoll are case-insensitive)
_mbsdec, _strdec, _wcsdec Move string pointer back one character
_mbsinc, _strinc, _wcsinc Advance string pointer by one character
_mbslen Get number of multibyte characters in multibyte-character string; dependent upon OEM code page
_mbsnbcat Append, at most, first n bytes of one multibyte-character string to another
_mbsnbcmp Compare first n bytes of two multibyte-character strings
_mbsnbcnt Return number of multibyte-character bytes within supplied character count
_mbsnbcpy Copy n bytes of string
_mbsnbicmp Compare n bytes of two multibyte-character strings, ignoring case
_mbsnbset Set first n bytes of multibyte-character string to specified character
_mbsnccnt Return number of multibyte characters within supplied byte count
_mbsnextc, _strnextc, _wcsnextc Find next character in string
_mbsninc. _strninc, _wcsninc Advance string pointer by n characters
_mbsspnp, _strspnp, _wcsspnp Return pointer to first character in given string that is not in another given string
_mbstrlen Get number of multibyte characters in multibyte-character string; locale-dependent
sprintf, _stprintf Write formatted data to a string
strcat, wcscat, _mbscat Append one string to another
strchr, wcschr, _mbschr Find first occurrence of specified character in string
strcmp, wcscmp, _mbscmp Compare two strings
strcoll, wcscoll, _stricoll, _wcsicoll, _strncoll, _wcsncoll, _strnicoll, _wcsnicoll Compare two strings using current locale code page information (_stricoll, _wcsicoll, _strnicoll, and _wcsnicoll are case-insensitive)
strcpy, wcscpy, _mbscpy Copy one string to another
strcspn, wcscspn, _mbscspn, Find first occurrence of character from specified character set in string
_strdup, _wcsdup, _mbsdup Duplicate string
strerror Map error number to message string
_strerror Map user-defined error message to string
strftime, wcsftime Format date-and-time string
_stricmp, _wcsicmp, _mbsicmp Compare two strings without regard to case
strlen, wcslen, _mbslen, _mbstrlen Find length of string
_strlwr, _wcslwr, _mbslwr Convert string to lowercase
strncat, wcsncat, _mbsncat Append characters of string
strncmp, wcsncmp, _mbsncmp Compare characters of two strings
strncpy, wcsncpy, _mbsncpy Copy characters of one string to another
_strnicmp, _wcsnicmp, _mbsnicmp Compare characters of two strings without regard to case
_strnset, _wcsnset, _mbsnset Set first n characters of string to specified character
strpbrk, wcspbrk, _mbspbrk Find first occurrence of character from one string in another string
strrchr, wcsrchr,_mbsrchr Find last occurrence of given character in string
_strrev, _wcsrev,_mbsrev Reverse string
_strset, _wcsset, _mbsset Set all characters of string to specified character
strspn, wcsspn, _mbsspn Find first substring from one string in another string
strstr, wcsstr, _mbsstr Find first occurrence of specified string in another string
strtok, wcstok, _mbstok Find next token in string
_strupr, _wcsupr, _mbsupr Convert string to uppercase
strxfrm, wcsxfrm Transform string into collated form based on locale-specific information
vsprintf, _vstprint Write formatted output using a pointer to a list of arguments
These routines operate on null-terminated single-byte character, wide-character, and multibyte-character strings. Use the buffer-manipulation routines, described in Buffer Manipulation, to work with character arrays that do not end with a null character.
String-Manipulation Routines
Routine Use
_mbscoll, _mbsicoll, _mbsncoll, _mbsnicoll Compare two multibyte-character strings using multibyte code page information (_mbsicoll and _mbsnicoll are case-insensitive)
_mbsdec, _strdec, _wcsdec Move string pointer back one character
_mbsinc, _strinc, _wcsinc Advance string pointer by one character
_mbslen Get number of multibyte characters in multibyte-character string; dependent upon OEM code page
_mbsnbcat Append, at most, first n bytes of one multibyte-character string to another
_mbsnbcmp Compare first n bytes of two multibyte-character strings
_mbsnbcnt Return number of multibyte-character bytes within supplied character count
_mbsnbcpy Copy n bytes of string
_mbsnbicmp Compare n bytes of two multibyte-character strings, ignoring case
_mbsnbset Set first n bytes of multibyte-character string to specified character
_mbsnccnt Return number of multibyte characters within supplied byte count
_mbsnextc, _strnextc, _wcsnextc Find next character in string
_mbsninc. _strninc, _wcsninc Advance string pointer by n characters
_mbsspnp, _strspnp, _wcsspnp Return pointer to first character in given string that is not in another given string
_mbstrlen Get number of multibyte characters in multibyte-character string; locale-dependent
sprintf, _stprintf Write formatted data to a string
strcat, wcscat, _mbscat Append one string to another
strchr, wcschr, _mbschr Find first occurrence of specified character in string
strcmp, wcscmp, _mbscmp Compare two strings
strcoll, wcscoll, _stricoll, _wcsicoll, _strncoll, _wcsncoll, _strnicoll, _wcsnicoll Compare two strings using current locale code page information (_stricoll, _wcsicoll, _strnicoll, and _wcsnicoll are case-insensitive)
strcpy, wcscpy, _mbscpy Copy one string to another
strcspn, wcscspn, _mbscspn, Find first occurrence of character from specified character set in string
_strdup, _wcsdup, _mbsdup Duplicate string
strerror Map error number to message string
_strerror Map user-defined error message to string
strftime, wcsftime Format date-and-time string
_stricmp, _wcsicmp, _mbsicmp Compare two strings without regard to case
strlen, wcslen, _mbslen, _mbstrlen Find length of string
_strlwr, _wcslwr, _mbslwr Convert string to lowercase
strncat, wcsncat, _mbsncat Append characters of string
strncmp, wcsncmp, _mbsncmp Compare characters of two strings
strncpy, wcsncpy, _mbsncpy Copy characters of one string to another
_strnicmp, _wcsnicmp, _mbsnicmp Compare characters of two strings without regard to case
_strnset, _wcsnset, _mbsnset Set first n characters of string to specified character
strpbrk, wcspbrk, _mbspbrk Find first occurrence of character from one string in another string
strrchr, wcsrchr,_mbsrchr Find last occurrence of given character in string
_strrev, _wcsrev,_mbsrev Reverse string
_strset, _wcsset, _mbsset Set all characters of string to specified character
strspn, wcsspn, _mbsspn Find first substring from one string in another string
strstr, wcsstr, _mbsstr Find first occurrence of specified string in another string
strtok, wcstok, _mbstok Find next token in string
_strupr, _wcsupr, _mbsupr Convert string to uppercase
strxfrm, wcsxfrm Transform string into collated form based on locale-specific information
vsprintf, _vstprint Write formatted output using a pointer to a list of arguments
#7
赵四老师手里干货真不少
可以搞个专题分享了
#8
赵老师手里干货不少呀 求分享分享
#9
不错,理解思想就行。 没必要在这个函数上继续优化。
#10
领教了!!!
#11
我的干货90%来自MSDN98.
#1
要不要判断一下src[i]不是字母的情况?
一般来说,对于非字母的字符(比如数字),toupper或tolower应该是保持原值不变的
一般来说,对于非字母的字符(比如数字),toupper或tolower应该是保持原值不变的
#2
不错,不过这样代码的时候应该有个注释,方便别人能理解。
我记得王爽的汇编语言里面有个这个,就是把第6位置1(大写)或置0(小写)。
#3
如果就拿src作为字符串来用,那么len未必有必要,直接用'\0'判断字符串结束即可。
#4
有道理
#5
加个len可能更灵活吧
#6
String Manipulation
These routines operate on null-terminated single-byte character, wide-character, and multibyte-character strings. Use the buffer-manipulation routines, described in Buffer Manipulation, to work with character arrays that do not end with a null character.
String-Manipulation Routines
Routine Use
_mbscoll, _mbsicoll, _mbsncoll, _mbsnicoll Compare two multibyte-character strings using multibyte code page information (_mbsicoll and _mbsnicoll are case-insensitive)
_mbsdec, _strdec, _wcsdec Move string pointer back one character
_mbsinc, _strinc, _wcsinc Advance string pointer by one character
_mbslen Get number of multibyte characters in multibyte-character string; dependent upon OEM code page
_mbsnbcat Append, at most, first n bytes of one multibyte-character string to another
_mbsnbcmp Compare first n bytes of two multibyte-character strings
_mbsnbcnt Return number of multibyte-character bytes within supplied character count
_mbsnbcpy Copy n bytes of string
_mbsnbicmp Compare n bytes of two multibyte-character strings, ignoring case
_mbsnbset Set first n bytes of multibyte-character string to specified character
_mbsnccnt Return number of multibyte characters within supplied byte count
_mbsnextc, _strnextc, _wcsnextc Find next character in string
_mbsninc. _strninc, _wcsninc Advance string pointer by n characters
_mbsspnp, _strspnp, _wcsspnp Return pointer to first character in given string that is not in another given string
_mbstrlen Get number of multibyte characters in multibyte-character string; locale-dependent
sprintf, _stprintf Write formatted data to a string
strcat, wcscat, _mbscat Append one string to another
strchr, wcschr, _mbschr Find first occurrence of specified character in string
strcmp, wcscmp, _mbscmp Compare two strings
strcoll, wcscoll, _stricoll, _wcsicoll, _strncoll, _wcsncoll, _strnicoll, _wcsnicoll Compare two strings using current locale code page information (_stricoll, _wcsicoll, _strnicoll, and _wcsnicoll are case-insensitive)
strcpy, wcscpy, _mbscpy Copy one string to another
strcspn, wcscspn, _mbscspn, Find first occurrence of character from specified character set in string
_strdup, _wcsdup, _mbsdup Duplicate string
strerror Map error number to message string
_strerror Map user-defined error message to string
strftime, wcsftime Format date-and-time string
_stricmp, _wcsicmp, _mbsicmp Compare two strings without regard to case
strlen, wcslen, _mbslen, _mbstrlen Find length of string
_strlwr, _wcslwr, _mbslwr Convert string to lowercase
strncat, wcsncat, _mbsncat Append characters of string
strncmp, wcsncmp, _mbsncmp Compare characters of two strings
strncpy, wcsncpy, _mbsncpy Copy characters of one string to another
_strnicmp, _wcsnicmp, _mbsnicmp Compare characters of two strings without regard to case
_strnset, _wcsnset, _mbsnset Set first n characters of string to specified character
strpbrk, wcspbrk, _mbspbrk Find first occurrence of character from one string in another string
strrchr, wcsrchr,_mbsrchr Find last occurrence of given character in string
_strrev, _wcsrev,_mbsrev Reverse string
_strset, _wcsset, _mbsset Set all characters of string to specified character
strspn, wcsspn, _mbsspn Find first substring from one string in another string
strstr, wcsstr, _mbsstr Find first occurrence of specified string in another string
strtok, wcstok, _mbstok Find next token in string
_strupr, _wcsupr, _mbsupr Convert string to uppercase
strxfrm, wcsxfrm Transform string into collated form based on locale-specific information
vsprintf, _vstprint Write formatted output using a pointer to a list of arguments
These routines operate on null-terminated single-byte character, wide-character, and multibyte-character strings. Use the buffer-manipulation routines, described in Buffer Manipulation, to work with character arrays that do not end with a null character.
String-Manipulation Routines
Routine Use
_mbscoll, _mbsicoll, _mbsncoll, _mbsnicoll Compare two multibyte-character strings using multibyte code page information (_mbsicoll and _mbsnicoll are case-insensitive)
_mbsdec, _strdec, _wcsdec Move string pointer back one character
_mbsinc, _strinc, _wcsinc Advance string pointer by one character
_mbslen Get number of multibyte characters in multibyte-character string; dependent upon OEM code page
_mbsnbcat Append, at most, first n bytes of one multibyte-character string to another
_mbsnbcmp Compare first n bytes of two multibyte-character strings
_mbsnbcnt Return number of multibyte-character bytes within supplied character count
_mbsnbcpy Copy n bytes of string
_mbsnbicmp Compare n bytes of two multibyte-character strings, ignoring case
_mbsnbset Set first n bytes of multibyte-character string to specified character
_mbsnccnt Return number of multibyte characters within supplied byte count
_mbsnextc, _strnextc, _wcsnextc Find next character in string
_mbsninc. _strninc, _wcsninc Advance string pointer by n characters
_mbsspnp, _strspnp, _wcsspnp Return pointer to first character in given string that is not in another given string
_mbstrlen Get number of multibyte characters in multibyte-character string; locale-dependent
sprintf, _stprintf Write formatted data to a string
strcat, wcscat, _mbscat Append one string to another
strchr, wcschr, _mbschr Find first occurrence of specified character in string
strcmp, wcscmp, _mbscmp Compare two strings
strcoll, wcscoll, _stricoll, _wcsicoll, _strncoll, _wcsncoll, _strnicoll, _wcsnicoll Compare two strings using current locale code page information (_stricoll, _wcsicoll, _strnicoll, and _wcsnicoll are case-insensitive)
strcpy, wcscpy, _mbscpy Copy one string to another
strcspn, wcscspn, _mbscspn, Find first occurrence of character from specified character set in string
_strdup, _wcsdup, _mbsdup Duplicate string
strerror Map error number to message string
_strerror Map user-defined error message to string
strftime, wcsftime Format date-and-time string
_stricmp, _wcsicmp, _mbsicmp Compare two strings without regard to case
strlen, wcslen, _mbslen, _mbstrlen Find length of string
_strlwr, _wcslwr, _mbslwr Convert string to lowercase
strncat, wcsncat, _mbsncat Append characters of string
strncmp, wcsncmp, _mbsncmp Compare characters of two strings
strncpy, wcsncpy, _mbsncpy Copy characters of one string to another
_strnicmp, _wcsnicmp, _mbsnicmp Compare characters of two strings without regard to case
_strnset, _wcsnset, _mbsnset Set first n characters of string to specified character
strpbrk, wcspbrk, _mbspbrk Find first occurrence of character from one string in another string
strrchr, wcsrchr,_mbsrchr Find last occurrence of given character in string
_strrev, _wcsrev,_mbsrev Reverse string
_strset, _wcsset, _mbsset Set all characters of string to specified character
strspn, wcsspn, _mbsspn Find first substring from one string in another string
strstr, wcsstr, _mbsstr Find first occurrence of specified string in another string
strtok, wcstok, _mbstok Find next token in string
_strupr, _wcsupr, _mbsupr Convert string to uppercase
strxfrm, wcsxfrm Transform string into collated form based on locale-specific information
vsprintf, _vstprint Write formatted output using a pointer to a list of arguments
#7
赵四老师手里干货真不少
可以搞个专题分享了
#8
赵老师手里干货不少呀 求分享分享
#9
不错,理解思想就行。 没必要在这个函数上继续优化。
#10
领教了!!!
#11
我的干货90%来自MSDN98.