zoukankan
html css js c++ java
截取字符串函数
截取字符串函数:解决了中文与英文截取不同的问题。
Code
1
字符串截取函数
#region
字符串截取函数
2
public
static
string
CutString(
string
inputString,
int
len)
3
{
4
5
ASCIIEncoding ascii
=
new
ASCIIEncoding();
6
int
tempLen
=
0
;
7
string
tempString
=
""
;
8
byte
[] s
=
ascii.GetBytes(inputString);
9
for
(
int
i
=
0
; i
<
s.Length; i
++
)
10
{
11
if
((
int
)s[i]
==
63
)
12
{
13
tempLen
+=
2
;
14
}
15
else
16
{
17
tempLen
+=
1
;
18
}
19
20
try
21
{
22
tempString
+=
inputString.Substring(i,
1
);
23
}
24
catch
25
{
26
break
;
27
}
28
29
if
(tempLen
>
len)
30
break
;
31
}
32
byte
[] mybyte
=
System.Text.Encoding.Default.GetBytes(inputString);
33
if
(mybyte.Length
>
len)
34
tempString
+=
"
…
"
;
35
36
return
tempString;
37
}
38
#endregion
Repeat中调用该函数:
Code
1
<
asp:Repeater ID
=
"
Repeater1
"
runat
=
"
server
"
>
2
<
ItemTemplate
>
3
<
a href
=
'
<%# "Bulletin/Details.aspx?BulletinID="+ DataBinder.Eval(Container.DataItem,"ID") %>
'
><%
# Warning.CutString(DataBinder.Eval(Container.DataItem,
"
Title
"
).ToString(),
22
)
%></
a
>
4
</
ItemTemplate
>
5
</
asp:Repeater
>
去除最后那个“|”字符
Code
1
private
string
ClearLastChar(
string
str)
2
{
3
if
(str
==
null
)
4
{
5
return
str;
6
}
7
else
8
{
9
if
(str.Length
>
0
)
10
{
11
return
str.Substring(
0
, str.LastIndexOf(
"
|
"
));
12
}
13
else
14
{
15
return
""
;
16
}
17
18
}
19
}
20
查看全文
相关阅读:
30天养成一个好习惯
ym——安卓巴士总结了近百个Android优秀开源项
内存泄漏以及常见的解决方法
Android学习笔记(四十):Preference的使用
Android中View绘制流程以及invalidate()等相关方法分析
NumberFormat 类
开发人员福利!ChromeSnifferPlus 插件正式登陆 Chrome Web Store
memset函数具体说明
分分钟教会你使用HTML写Web页面
UVA 465 (13.08.02)
原文地址:https://www.cnblogs.com/zhangchenliang/p/1035703.html
最新文章
EBS OAF 开发中的OAMessageRadioGroup控件
控制默认使用360浏览器极速模式
设计模式——行为型模式(一)
对JAVA Bean使用PropertyDescriptor反射调用JAVA方法
VS2008下直接安装使用Boost库1.46.1版本号
教你用笔记本破解无线路由器password
大众点评笔试题最后两题题解
开发人员必备的6款源代码搜索引擎
有感PMI Exam Dev Workshop
数据结构之图(存储结构、遍历)
热门文章
wifi项目源码
C/C++ 用libcurl库进行http通讯网络编程
linuxtoy.org资源
正则表达式中各种字符的含义
结构体中定义函数指针
easycwmp的交叉编译
C语言柔性数组
op应用:官方,wifidog,portal,uci,luci,脚本,框架,usb
linux awk命令详解,使用system来内嵌系统命令, awk合并两列
黑盒之嵌入式操作系统鲁棒性研究
Copyright © 2011-2022 走看看