JSP处理字符串问题,请赐教:)

geebean 2003-08-19 10:48:51
请问何处有jsp函数库的文档下载?
我想处理一些字符串,可是却不知有什么函数可用
例如: 我想将 "Y01-D-23" 字符串按"-"分解成三部分
a1="Y01" ;
a2="D";
a3="23" ;
如何实现?谢谢
...全文
37 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
pnileotgx 2003-08-20
  • 打赏
  • 举报
回复
hehe !有新的为什么不用呢! 或者自己专门写一个类!实现该方法就ok !
rockrabbit 2003-08-20
  • 打赏
  • 举报
回复
Maybe you could write a public method in your package.
rockrabbit 2003-08-20
  • 打赏
  • 举报
回复
The method that named split was a new method and learned from vb.
geebean 2003-08-20
  • 打赏
  • 举报
回复
这样啊?
那我的版本可能不够哦
用以前的方法真是太麻烦了。。。
adolfpan 2003-08-20
  • 打赏
  • 举报
回复
split method is new to String Class from JDK1.4
geebean 2003-08-20
  • 打赏
  • 举报
回复
请问使用split函数是否要声明什么呢?

我出现了如下错误:
Method split(java.lang.String) not found in class java.lang.String. files = DDF_CODE.split("-");
zzgl 2003-08-20
  • 打赏
  • 举报
回复
String aaa = "123456";
我要取前4位
aaa="1234";

虽然可以用sql
select substring("123456",1,4) as bbb

jsp有没有函数可以用了?

zxdhaha 2003-08-20
  • 打赏
  • 举报
回复
同意楼上的说法
shaokun305 2003-08-20
  • 打赏
  • 举报
回复
用split()函数来实现:

String modified="Y01-D-23";
String[] files = modified.split("-");

// 输出
for (int i = 0; i < files.length; i++)
{
System.out.println(files[i]);
}

cuihao 2003-08-19
  • 打赏
  • 举报
回复
Vector s_sys=new Vector();
//将软件操作平台的字符串按照“/”分割开
StringTokenizer st=new StringTokenizer(soft_sys,"/");
while(st.hasMoreTokens())
{
s_sys.addElement(st.nextToken());
}
betterjonah 2003-08-19
  • 打赏
  • 举报
回复
public int indexOf(int ch,
int fromIndex)
Returns the index within this string of the first occurrence of the specified character, starting the search at the specified index.
If a character with value ch occurs in the character sequence represented by this String object at an index no smaller than fromIndex, then the index of the first such occurrence is returned--that is, the smallest value k such that:

(this.charAt(k) == ch) && (k >= fromIndex)

is true. If no such character occurs in this string at or after position fromIndex, then -1 is returned.
There is no restriction on the value of fromIndex. If it is negative, it has the same effect as if it were zero: this entire string may be searched. If it is greater than the length of this string, it has the same effect as if it were equal to the length of this string: -1 is returned.


Parameters:
ch - a character.
fromIndex - the index to start the search from.
Returns:
the index of the first occurrence of the character in the character sequence represented by this object that is greater than or equal to fromIndex, or -1 if the character does not occur.


substring
public String substring(int beginIndex,
int endIndex)
Returns a new string that is a substring of this string. The substring begins at the specified beginIndex and extends to the character at index endIndex - 1. Thus the length of the substring is endIndex-beginIndex.
Examples:

"hamburger".substring(4, 8) returns "urge"
"smiles".substring(1, 5) returns "mile"


Parameters:
beginIndex - the beginning index, inclusive.
endIndex - the ending index, exclusive.
Returns:
the specified substring.
Throws:
IndexOutOfBoundsException - if the beginIndex is negative, or endIndex is larger than the length of this String object, or beginIndex is larger than endIndex.

81,092

社区成员

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

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