请问一个字符串处理的问题。

dql_77 2003-10-16 12:28:53
str1="2003080000000218$2003080000000219$2003080000000070$2003090000000247$2003090000000462$";
str2="2003080000000070$";
如果str1包含str2返回为真,反之返回为假。
请问如何写。
...全文
62 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
kevincom 2003-10-16
  • 打赏
  • 举报
回复
安楼上:qixin_lover(一品) 所说:
如果i为-1则不包含,否则就是包含。
qixin_lover 2003-10-16
  • 打赏
  • 举报
回复
int i=str1.indexOf(str2);
i里是str2在str1中的位置,若是0,就是没有,不包含
lovelong1981 2003-10-16
  • 打赏
  • 举报
回复
indexOf

public int indexOf(int ch)


Returns the index within this string of the first occurrence of the specified character.

Parameters:

ch - a character.

Returns:

the index of the first occurrence of the character in the character sequence represented by this object, or -1 if the character does not occur.

indexOf

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.

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.

indexOf

public int indexOf(String str)


Returns the index within this string of the first occurrence of the specified substring.

Parameters:

str - any string.

Returns:

if the string argument occurs as a substring within this object, then the index of the first character of the first such substring is returned; if it does not occur as a substring, -1 is returned.

indexOf

public int indexOf(String str,
int fromIndex)


Returns the index within this string of the first occurrence of the specified substring, starting at the specified index.

Parameters:

str - the substring to search for.

fromIndex - the index to start the search from.

Returns:

If the string argument occurs as a substring within this object at a starting index no smaller than fromIndex, then the index of the first character of the first such substring is returned. If it does not occur as a substring starting at fromIndex or beyond, -1 is returned.
yalig 2003-10-16
  • 打赏
  • 举报
回复
天哪!int i=str1.indexOf(str2); 这样就可以了。
yalig 2003-10-16
  • 打赏
  • 举报
回复
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.util.StringTokenizer"%>
<%
try{



StringTokenizer a, b;
String str1, str2;
str1="2003080000000218$2003080000000219$2003080000000070$2003090000000247$2003090000000462$";
str2="2003080000000218$";

a = new StringTokenizer(str1, "$");
b = new StringTokenizer(str2, "$");
String b2=b.nextToken();
//
while(a.hasMoreElements()){
//out.print(a.nextToken() + "<br>");
//return;
if(b2.equals(a.nextToken())){
out.print("包含<hr>");
}

}

}catch(Exception ex){
out.print(ex.toString());
}
%>

81,091

社区成员

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

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