Partager via


_StrLen( ) API Library Routine

Returns the length in bytes of the specified null-terminated string.

int _StrLen(char FAR *string)
char FAR *string;            /* String to be measured. */

Example

The following example is similar to the Visual FoxPro function LEN( ), but can't handle strings with embedded '\0'.

Visual FoxPro Code

SET LIBRARY TO STRLEN  
? STRLEN("Hello") && returns 5

C Code

#include <pro_ext.h>

void NullTerminate(Value FAR *cVal)
{
   if (!_SetHandSize(cVal->ev_handle, cVal->ev_length + 1)) {
      _Error(182); // "Insufficient memory"
   }
   ((char FAR *) _HandToPtr(cVal->ev_handle))[cVal->ev_length] = '\0';
}

FAR Example(ParamBlk FAR *parm)
{
   NullTerminate(&parm->p[0].val);
   _HLock(parm->p[0].val.ev_handle);
   _RetInt(_StrLen(_HandToPtr(parm->p[0].val.ev_handle)), 10);
   _HUnLock(parm->p[0].val.ev_handle);
}

FoxInfo myFoxInfo[] = {
   {"STRLEN", (FPFI) Example, 1, "C"},
};
FoxTable _FoxTable = {
   (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo
};

See Also

_StrCmp( ) API Library Routine | _StrCpy( ) API Library Routine | LEN( ) Function | String Manipulation Routines