字符串's tag archives

ASP来实现UTF8转换GB2312国标码

ASP来实现UTF8转换GB2312国标码-GB2312转UTF-8'个人代码风格注释(变量名中第一个小写字母表表示变量类型) 'i:为Integer型; 's:为String; Function U2UTF8(Byval a_iNum)     Dim sResult,sUTF8     Dim iTemp,iHexNum,i    iHexNum = Trim(a_iNum)    If iHexNum = "" Then         Exit Function     End If    sResult = ""    If (iHexNum < 128) Then         sResult = sResult & iHexNum     ElseIf...

在字符串指定位置插入一段字符串

//插入一段字符串 function str_insert($str, $i, $substr) { for($j=0; $j<$i; $j++){ $startstr .= $str[$j]; } for ($j=$i; $j<strlen($str); $j++){ $laststr .= $str[$j]; } $str = ($startstr . $substr . $laststr); return...

判断是否为指定长度内字符串

//----------------------------------------------------------------------------------- ------- // 函数名:CheckLengthBetween($C_char, $I_len1, $I_len2=100) // 作 用:判断是否为指定长度内字符串 // 参 数:$C_char(待检测的字符串) // $I_len1 (目标字符串长度的下限) // $I_len2 (目标字符串长度的上限) // 返回值:布尔值 // 备...

UTF-8 GBK下PHP获取字符串长度

UTF-8 GBK下PHP获取字符串长度,是langwan写的,贴过来大家分享,完美的解决了PHP下获取UTF-8或者GBK字符集的字符串长度问题!/** 统计字符串长度 *@author langwan *@param $str 被统计字符串*/function sstrlen($str) { global $charset; $n = 0; $p = 0; $c = ''; $len = strlen($str); if($charset == 'utf-8') { for($i = 0; $i < $len; $i++) { $c = ord($str{$i}); if($c > 252) { $p = 5; } elseif($c > 248) { $p = 4; }...

中文字符长度

//中文字符长度,一个中文长度为1。 function cstrlen($str){ $n = 0; $p = 0; $c = ''; $len = strlen($str);for($i = 0; $i < $len; $i++) { $c = ord($str{$i}); if($c > 127) { $p = 1; } else { $p = 0; } $i+=$p;$n++; }return...

截取字符串-InterceptString

'************* 截取字符串 **************function InterceptString(txt,length) txt=trim(txt) x = len(txt) y = 0 if x >= 1 then for ii = 1 to x if asc(mid(txt,ii,1)) < 0 or asc(mid(txt,ii,1)) >255 then '如果是汉字 y = y + 2 else y = y + 1 end if if y >= length then txt = left(trim(txt),ii) '字符串限长 exit for end if next InterceptString = txt else InterceptString = "" end ifEnd...

测字符串长度-CheckStringLength

'*************测字符串长度**************Function CheckStringLength(txt) txt=trim(txt) x = len(txt) y = 0 for ii = 1 to x if asc(mid(txt,ii,1)) < 0 or asc(mid(txt,ii,1)) >255 then '如果是汉字 y = y + 2 else y = y + 1 end if next CheckStringLength = yEnd...

UTF8编码转Unicode

function Utf8ToUnicode(strUtf8) { var bstr = ""; var nTotalChars = strUtf8.length; // total chars to be processed. var nOffset = 0; // processing point on strUtf8 var nRemainingBytes = nTotalChars; // how many bytes left to be converted var nOutputPosition = 0; var iCode, iCode1, iCode2; // the value of the unicode.while (nOffset < nTotalChars) { iCode = strUtf8.charCodeAt(nOffset); if ((iCode &...

iscn-判断是否有包括中文的字符串

/* 可用于用户名等不允许使用出现中文字符的地方 itlearner整理发布 */ $str = "dd*(*d"; if (iscn($str)) { echo "包括中文的字符串"; } else { echo "不包括中文的字符串"; }function iscn($str){ if (preg_match("/.*[".chr(0xa1)."-".chr(0xff)."]+.*/", $str)) { return true; } else { return...