Tuesday, July 19, 2011

_mbsspnp, _strspnp, _wcsspnp, _tcsspnp

unsigned char *_mbsspnp( const unsigned char *string1,   const unsigned char *string2 );

Routine Required Header Compatibility
_mbsspnp Win 95, Win NT
_strspnp Win 95, Win NT
_wcsspnp Win 95, Win NT

Libraries
LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version

Return Value:
_strspnp, _wcsspnp, and _mbsspnp return a pointer to the first character in string1 that does not belong to the set of characters in string2. Each of these functions returns NULL if string1 consists entirely of characters from string2. For each of these routines, no return value is reserved to indicate an error.

Parameters
string1 : Null-terminated string to search
string2 :   Null-terminated character set

Remarks:
The _mbsspnp function returns a pointer to the multibyte character that is the first character in string1 that does not belong to the set of characters in string2. _mbsspnp recognizes multibyte-character sequences according to the multibyte code page currently in use. The search does not include terminating null characters.

The generic-text function _tcsspnp, defined in TCHAR.H, maps to _mbsspnp if _MBCS has been defined, or to _wcsspnp if _UNICODE has been defined. Otherwise _tcsspnp maps to _strspnp. _strspnp and _wcsspnp are single-byte character and wide-character versions of _mbsspnp. _strspnp and _wcsspnp behave identically to _mbsspnp otherwise; they are provided only for this mapping and should not be used for any other reason. For more information, see Using Generic-Text Mappings and Appendix B, Generic-Text Mappings.

MSDN Example:
/* STRSPN.C: This program uses strspn to determine  the length of the segment in the string "cabbage"
* consisting of a's, b's, and c's. In other words,  it finds the first non-abc letter.*/

#include
#include
void main( void )
{
   char string[] = "cabbage";
   int result;
   result = strspn( string, "abc" );
   printf( "The portion of '%s' containing only a, b, or c "  "is %d bytes long\n", string, result );
}

OutputThe portion of 'cabbage' containing only a, b, or c is 5 bytes long

See my Example , that will give you clear picture and understanding:
Sample code from my project:
void CUnicodeCharDlg::OnBnClickedButton2()

{
   CString csData;
   m_edit2.GetWindowText(csData);
   UpdateData(TRUE);
   static TCHAR * lpszValidChars = _T("ABCDEFGHIJKLMNOPQRSTUVWXYZ");

    // szText is the string you wanna check for invalid chracters
    if     (_tcsspnp(csData, lpszValidChars) != 0)
         {   MessageBox("Invalid Input Characters!", "Error", 0); }

         else {  MessageBox("Thats Correct Input!", "Great", 0); }
}

No comments:

Post a Comment

Health Benefits of Cashews

  Benefits of Cashews. Healthy food is an integral part of healthy body. Regular exercises such as Yoga and healthy diet is important to...