JavaScript で ShiftJIS での文字列のバイト数は以下でもとめる。
(半角は1バイト,全角は2バイト計算)
var iLength;
var iCnt;
iLength = 0;
if( strValue.length == 0 ) return iLength;
for( iCnt = 0; iCnt < strValue.length; iCnt++ ) {
strTemp = escape( strValue.charAt(iCnt) );
if( strTemp.length < 4 )
iLength++;
else
iLength += 2;
}
return iLength;
参照