用c#操作字符不太熟悉,请大家帮帮忙'**************************************************
'函数名:gotTopic
'作 用:截字符串,汉字一个算两个字符,英文算一个字符
'参 数:str ----原字符串
' strlen ----截取长度
'返回值:截取后的字符串
'**************************************************
function gotTopic(str,strlen)
if str="" then
gotTopic=""
exit function
end if
dim l,t,c, i
str=replace(replace(replace(replace(str," "," "),""",chr(34)),">",">"),"<","<")
l=len(str)
t=0
for i=1 to l
c=Abs(Asc(Mid(str,i,1)))
if c>255 then
t=t+2
else
t=t+1
end if
if t>=strlen then
gotTopic=left(str,i) & "…"
exit for
else
gotTopic=str
end if
next
gotTopic=replace(replace(replace(replace(gotTopic," "," "),chr(34),"""),">",">"),"<","<")
end function
'函数名:gotTopic
'作 用:截字符串,汉字一个算两个字符,英文算一个字符
'参 数:str ----原字符串
' strlen ----截取长度
'返回值:截取后的字符串
'**************************************************
function gotTopic(str,strlen)
if str="" then
gotTopic=""
exit function
end if
dim l,t,c, i
str=replace(replace(replace(replace(str," "," "),""",chr(34)),">",">"),"<","<")
l=len(str)
t=0
for i=1 to l
c=Abs(Asc(Mid(str,i,1)))
if c>255 then
t=t+2
else
t=t+1
end if
if t>=strlen then
gotTopic=left(str,i) & "…"
exit for
else
gotTopic=str
end if
next
gotTopic=replace(replace(replace(replace(gotTopic," "," "),chr(34),"""),">",">"),"<","<")
end function
解决方案 »
- 如何用C#读取ppt文件的第一和第二页并将这两页分别保存为两张图片
- [100分],为什么一加上Path属性,就不能生成Cookie呢??在线,对了,200分。
- 做博客为什么有Res ,是什么,为什么要这样做啊?
- 我在 框架页window.open一窗体,然后想要从PersonRequisition。ASPX 这窗体转入框架内的另一页面,可是转不到框架内,请各位大虾帮忙。。
- 关于Repeater控件的2个问题
- 怎样用ASP.NET代码在服务器端正确创建一个.htm文件
- 怎样取得我上网的真实IP地址
- 继承IHttpHandler实现全局图片水印
- xml菜鸟求教:为什么我输入一行,vs2005.net就死掉
- JS函数中给变量赋值的问题
- 不支持“word-break”后,我们该怎么办?
- 高分求助ActiveX控件问题!
s = replace (s,""",chr(34))
string gotTopic(string strSrc,int iLength)
{
if (strSrc==null||strSrc.Length==0) return null; strSrc=strSrc.Replace(" "," ");
strSrc = strSrc.Replace(""", Convert.ToString((char)34));
strSrc=strSrc.Replace(">",">");
strSrc=strSrc.Replace("<","<"); int iCurPos =0;
int iCurLength=strSrc.Length; for(int i=0;i<iCurLength;i++)
{
if (Math.Abs(char.Parse(strSrc.Substring(i,1)))>255)
iCurPos+=2;
else
iCurPos+=1; if (iCurPos>=iLength)
{
strSrc=strSrc.Substring(0,i) +"…";
break;
}
} strSrc = strSrc.Replace(" ", " ");
strSrc = strSrc.Replace(Convert.ToString((char)34), """);
strSrc = strSrc.Replace(">", ">");
strSrc = strSrc.Replace("<", "<");
return strSrc;
}