您的位置:首页 > 其它

读取中文字符串长度 AND 按长度截取中文字符串中字符

2006-06-13 11:15 561 查看
public int Length(string strLen)
{
int l,t,c;
int i;
l=strLen.Length ;
t=l;
for( i=0;i<l;i++)
{
c=(int)strLen[i];
if( c<0)
{
c=c+65536;
}
if (c>255)
{
t=t+1;
}
}
return t;
}

public string Substring(string strValue, int startIndex, int length)
{
int iStartTemp = 0;
int iTemp = 0;
string returnString = "";
if(Length(strValue) > startIndex)
{
for(int i=0;i<strValue.Length;i++)
{
int c = (int)strValue[i];
if( c<0)
c += 65536;
if (c>255)
iTemp += 2;
else
iTemp += 1;
if(iTemp > startIndex)
{
iStartTemp = i;
break;
}
}
}
else
return returnString;

iTemp = 0;
if(Length(strValue) >(startIndex + length))
{
for(int i= iStartTemp;i<strValue.Length;i++)
{
int c = (int)strValue[i];
if( c<0)
c += 65536;
if (c>255)
iTemp += 2;
else
iTemp += 1;
if(iTemp > length)
break;
else
returnString += strValue[i].ToString();
}
}
else
{
returnString = strValue.Substring(iStartTemp);
}
return returnString;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐