在 C++ 中:
/*---------------------------------------------------------------------------*/
/* thai_tcslen */
/*---------------------------------------------------------------------------*/
short thai_tcslen(_TCHAR *buff)
{
short bufpos;
short normal_length;
short thai_length;
thai_length=0;
normal_length = _tcslen(buff);
for (bufpos = 0; bufpos < normal_length; bufpos++) {
if ( *(buff+bufpos) != _T('Ñ')/*mai han na kaad*//*-047*/
&& *(buff+bufpos) != _T('Ô')/*sara ee *//*-044*/
&& *(buff+bufpos) != _T('Õ')/*sara eeeee *//*-043*/
&& *(buff+bufpos) != _T('Ö')/*sara uu *//*-042*/
&& *(buff+bufpos) != _T('×')/*sara uuuuu *//*-041*/
&& *(buff+bufpos) != _T('Ø')/*sara oo *//*-040*/
&& *(buff+bufpos) != _T('Ù')/*sara ooooo *//*-039*/
&& *(buff+bufpos) != _T('ç')/*mai tai khoo *//*-025*/
&& *(buff+bufpos) != _T('è')/*mai aek *//*-024*/
&& *(buff+bufpos) != _T('é')/*mai toe *//*-023*/
&& *(buff+bufpos) != _T('ê')/*mai cha ta wah *//*-022*/
&& *(buff+bufpos) != _T('ë')/*mai tree *//*-021*/
&& *(buff+bufpos) != _T('ì')/*ka ran *//*-020*/
) {
thai_length++;
}
}
return(thai_length);
} /* thai_tcslen */
在 VB6 中:
Public Function ThaiStringLength(ByRef ThaiString As String) As Long
Dim b As String, noLengthChars(13) As Byte
b = ThaiString
noLengthChars(0) = 209
noLengthChars(1) = 212
noLengthChars(2) = 213
noLengthChars(3) = 214
noLengthChars(4) = 215
noLengthChars(5) = 216
noLengthChars(6) = 217
noLengthChars(7) = 231
noLengthChars(8) = 232
noLengthChars(9) = 233
noLengthChars(10) = 234
noLengthChars(11) = 235
noLengthChars(12) = 236
Dim o As Long
For o = 0 To 12
If InStr(b, Chr(noLengthChars(o))) > 0 Then
b = Replace(b, Chr(noLengthChars(o)), "")
End If
Next
ThaiStringLength = Len(b)
End Function