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.
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.
解决方案 »
- 求助 数据库操作
- 用Applet还是ActiveX,大家给点意见?
- 感觉比较难,如何将一个字符串中间的2个子字符串中间的字符串取出来~~~~~~~~~~~
- 如何显示Oracle数据库中Date字段中的时间?
- 求jsp and java电子版入门教程
- 聊天室小问题,希望解决,在线等待,谢谢
- 如果关闭Tomcat的MS-DOS窗口
- jsp如何发送邮件?
- out.print(在线等)
- 乱码问题(不是简单的new String(strNeedConvert.getBytes("ISO8859_1"),"gb2312");)
- 用过jk_nt_service的请进。(我已经郁闷了一天了)
- tomcat安装问题,一定给分!!!
//将软件操作平台的字符串按照“/”分割开
StringTokenizer st=new StringTokenizer(soft_sys,"/");
while(st.hasMoreTokens())
{
s_sys.addElement(st.nextToken());
}
String[] files = modified.split("-"); // 输出
for (int i = 0; i < files.length; i++)
{
System.out.println(files[i]);
}
我要取前4位
aaa="1234";虽然可以用sql
select substring("123456",1,4) as bbbjsp有没有函数可以用了?
Method split(java.lang.String) not found in class java.lang.String. files = DDF_CODE.split("-");