java 查找某字符串

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class Test {
public static void main(String[] args) throws IOException{
//目标字符串
String target = "20000";
//注意修改文件路径
BufferedReader br = new BufferedReader(new FileReader("D:/ks.txt"));
String line = null;
while(null != (line = br.readLine())){
if(line.contains(target)){
//截取最后一个分号以后的部分,并作为结果输出
System.out.println("结果为:"+ line.substring(line.lastIndexOf(";") + 1));
break;
}
}
br.close();
}
}

② java 如何查找匹配的字符和字符串

你可以自己写个方法的!
从返回的第一个位置开始substring,同时记住位置。

public int[] getOffset(String str,String s){
int[] arr=new int[str.length];
int j=1;
while(str.indexOf(s)!=-1){
int i=str.indexOf(s);
if(j==1){
arr[j-1]=i;
}else{
arr[j-1]=i+arr[j-2]+1;
}
String st=str.substring(i+1);
System.out.println(st);
str=st;
j++;
System.out.println("j="+j);
}
return arr;
}

public static void main(String[] args) {

String str="abcaabbddab";
StringText st=new StringText();
int[] i=st.getOffset(str, "ab");
for(int j:i){
System.out.println(j);
}
}

③ Java实现在字符串中查找字符串

把上抄上面那仁兄袭的改改,不知合不合适:
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Find {
public static void main(String[] args) {
String ss = "...qqqq:hello-a;hello-b;hello-c;hello-d,....";
Matcher matcher = Pattern.compile("(hello-.)").matcher(ss);
int index = 0;
while (matcher.find()) {
index++;
if (matcher.group(1).equals("hello-c")) {
break;
}
}
System.out.println(index);
}
}

④ JAVA中如何查找字符串

问题很简单:
1.首先,你的数据源是数组,那么要想对每一个值作操作,必须遍历,所以就有如下代码

for(int i=0;i<A.length;i++){
...
}

2.在循环当中,数组中的每一个正在遍历的元素,就是:A[i];

3.String是java的一个字符串处理类,他有一个非常好用的方法就是,
public boolean startsWith(String prefix),测试此字符串是否以指定的前缀开始。 所以:A[i].startsWith("C")如果返回true,那么他就是以C开头的。

4.综上所述,实现很简单,完成代码如下:
public class Test{
public static void main(String[] args){
String[] A ={"CSDF","FDS","CFDSA","DFS","FET"};
for(int i=0;i<A.length;i++){
if(A[i].startsWith("C")){
System.out.println(A[i]);
}
}
}
}

总结:
临时写的,代码没有经过测试,但敢保证其正确性的几率很大,祝你成功。

⑤ java怎么查找字符串中是否包含某个字段

方法:

1、描述:java.lang.String.contains() 方法返回true,当且仅当此字符串包含指定的char值序列

2、声明:如下图

⑥ java中怎么实现在一个字符串中查找其中的关键字。

public class $ {

public static void main(String... _) {

String str = "123456789 abcdefg hijklmn...";

System.out.println(str.indexOf("456"));
System.out.println(str.indexOf("45a"));
}
}

结果:
3
-1

如果有,就返回他的起始位置回,注意是从0开始
没有答,就返回-1

用循环

String[] key = { "456", "abc", "45a" };
String str = "123456789 abcdefg hijklmn...";

for (int i = 0; i < key.length; i++) {
System.out.println(key[i] + "的起始位置:" + str.indexOf(key[i]));
}

⑦ JAVA中怎样在一个字符串中查找给定的子字符串

调用类java.lang.String
的以下方法都可以:

public int indexOf(String str)
返回指定子字符串在此字符串中第一次出现处的索引。
参数:
str - 任意字符串。
返回:
如果字符串参数作为一个子字符串在此对象中出现,则返回第一个这种子字符串的第一个字符的索引;如果它不作为一个子字符串出现,则返回 -1。

public int indexOf(String str,int fromIndex)
返回指定子字符串在此字符串中第一次出现处的索引,从指定的索引开始。
参数:
str - 要搜索的子字符串。
fromIndex - 开始搜索的索引位置。
返回:
指定子字符串在此字符串中第一次出现处的索引,从指定的索引开始。

public int lastIndexOf(String str)
返回指定子字符串在此字符串中最右边出现处的索引。将最右边的空字符串 "" 视为出现在索引值 this.length() 处。
参数:
str - 要搜索的子字符串。
返回:
如果字符串参数作为一个子字符串在此对象中出现一次或多次,则返回最后一个这种子字符串的第一个字符。如果它不作为一个子字符串出现,则返回 -1。

public int lastIndexOf(String str,int fromIndex)
返回指定子字符串在此字符串中最后一次出现处的索引,从指定的索引开始反向搜索。
参数:
str - 要搜索的子字符串。
fromIndex - 开始搜索的索引位置。
返回:
指定子字符串在此字符串中最后一次出现处的索引。

⑧ java中如何查找字符串中的'\'

可以用正则表达式.
如果要表示java源码中的正则表达式的一个正常的'\'字符,则需要这样表示'\\\\',其中第一第三个'\'均表示java编译器中的转义字符第二个则表示正则表达式中的转义字符,从而把第四个'\'转义为正则表达式中一个普通的'\'字符

⑨ java如何实现在一个字符串中查找另一个字符串

要判断boy是不是后者中的一部分,不用循环,只要用String类的indexOf函数就行了。
代码如下:
public class HH {
public static void main(String[] args) {
内String s="he is a boy";
int result=s.indexOf("boy");
if(result>=0){
System.out.println("boy是容he is a boy的一部分");
}else{
System.out.println("boy不是he is a boy的一部分");
}
}
}
运行结果:
boy是he is a boy的一部分

⑩ java 如何从一个字符串中 找出 我所需要的字符

你可以尝试一下找到time=的位置,在找到ms的位置,这样去截取字符串,应该就可以了