有没有好的JSP截取字符串的函数?

kaxi 2003-09-17 01:58:34
支持中英文混合 截取后自动在字符串后边加上...
...全文
247 13 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
singnet 2003-09-17
  • 打赏
  • 举报
回复
int i=a.indexOf('X');
String str=a.substring(0,i);
aku0708 2003-09-17
  • 打赏
  • 举报
回复
substring()
dugang106 2003-09-17
  • 打赏
  • 举报
回复
cbhyk的程序可用
偶试了
timtin0361 2003-09-17
  • 打赏
  • 举报
回复
substring() 取子串

append() 串后面加串


参数在jbuilder的帮助里去查
redstarstar 2003-09-17
  • 打赏
  • 举报
回复
可以看看Apache中的Jakarta中的Commons项目。里面提供了一个org.apache.commons.lang.StringUtils的类,其中的关于截取字符的方法应该够多了。

http://jakarta.apache.org/commons/lang/api/org/apache/commons/lang/StringUtils.html
shuiaaa 2003-09-17
  • 打赏
  • 举报
回复
substring
csdnxw 2003-09-17
  • 打赏
  • 举报
回复
substring()
indexOf()
indexOflast()
一般也就这么几个,有没有jdk的帮助?上面的String类说的很明白
cbhyk 2003-09-17
  • 打赏
  • 举报
回复
自已写一个:
public class Test
{
public static String limitLength(String s, int length)
{
int bytes = 0;
StringBuffer buf = new StringBuffer();
for(int i=0; i<s.length() && bytes < length; i++)
{
char c = s.charAt(i);
if(c > 255)
{
if(bytes + 2 > length)
break;
bytes += 2;
}
else
bytes++;
buf.append(c);
}
return buf.toString();
}

public static void main(String[] args)
{
System.out.println(limitLength("abcd中文1234", 7) + "...");
}
}
liuxiaobo8590 2003-09-17
  • 打赏
  • 举报
回复
substring()
indexOf()
indexOflast()
smartzhang 2003-09-17
  • 打赏
  • 举报
回复
indexof
split jdk1.4
fft123 2003-09-17
  • 打赏
  • 举报
回复
substring()
支持中英文要你的页面编码支持或加字符集
加上...要自己手动的连接字符串
lang11zi 2003-09-17
  • 打赏
  • 举报
回复
substring()
onizuka5211 2003-09-17
  • 打赏
  • 举报
回复
我自己写的,你看一下吧,可能不太好,
package tools;

import java.io.PrintStream;

public class strLen
{

public strLen()
{
}

public static void main(String args[])
{
}

public String getStr(String s, int i)
{
String s1 = new String("");
int j = s.trim().getBytes().length;
try
{
if(j > i)
{
byte abyte0[] = s.getBytes();
s1 = new String(abyte0, 0, i);
int k = s1.length();
s1 = s1.substring(0, k - 1);
s1 = s1 + "....";
} else
{
s1 = s;
}
}
catch(Exception exception)
{
System.out.println(exception.getMessage());
}
return s1;
}
}

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧