A. 在java如何查找字元串位置

InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
System.out.println("Please input data:");
String data = br.readLine();
while(data==null||data.trim().length()==0){
data = br.readLine();
}
System.out.println("you data is :"+data);
System.out.println("Please input position:");
String[] p = br.readLine().split(",");
for (String string : p) {
System.out.println(string);
}
int[] postion = new int[data.length()];
int i=0;
for (String string : p) {
postion[i]= Integer.parseInt(p[i]);
i++;
}
System.out.println("this Result:");
for(int y=0;y<postion.length&&postion[y]>0;y++){
char c = data.charAt(postion[y]-1);
System.out.print(c);
}

B. java中如何查找字元串中的'\'

可以用正則表達式.
如果要表示java源碼中的正則表達式的一個正常的'\'字元,則需要這樣表示'\\\\',其中第一第三個'\'均表示java編譯器中的轉義字元第二個則表示正則表達式中的轉義字元,從而把第四個'\'轉義為正則表達式中一個普通的'\'字元

C. 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);
}
}

D. 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();
}
}

E. 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);
}
}

F. Java查找字元串中是否包含

import java.util.Scanner;
import org.apache.commons.lang3.StringUtils;
/**
* @author:
* @description:
*/
public class Test {
static int count = 0;
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("請輸入字元串:");
String line1 = scanner.nextLine();
System.out.println("請輸入包含的字元串:");
String line2 = scanner.nextLine();
int count = sort(line2, line1);
System.out.println("首次出現的位置:"+(line1.indexOf(line2)+1)+","+"共出現:"+count+"次");
}
public static int sort(String t, String s) {

int indexOf = s.indexOf(t);
if(indexOf==-1){
System.out.println("未找到指定的字元串!");
}else{
count++;
String string = s.substring(indexOf+1,s.length());
if(!StringUtils.isBlank(string)){
sort(t, string);
}
}
return count;

}
}

G. 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]);
}
}
}
}

總結:
臨時寫的,代碼沒有經過測試,但敢保證其正確性的幾率很大,祝你成功。

H. 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]));
}

I. 編一個JAVA程序,字元串數組中查找一個指定的字元串。

List list = SearchL;
String s1 = list.getString(list.getSelectedIndex());
int i1 = s1.lastIndexOf(':', s1.length());
String s4 = s1.substring(i1 + 1, s1.length());
int j1 = Integer.parseInt(s4, 10);
DrawStr.cline = j1;
GuoCPU.setCurrent(BackDis);
DrawStr.cline = j1;
} else
if (OpenFun == 2)
{
List list1 = SearchL;
int k = list1.getSelectedIndex();
String s2 = list1.getString(list1.getSelectedIndex());
String s5 = s2.substring(0, 3);
System.out.println("285241331= " + s5);
int k1 = Integer.parseInt(s5) - 1;
System.out.println("filej1= " + k1);
System.out.println("搜索文本FilePaths[filej-1]=" + FilePaths[k1]);
GuoCPU.ExplorerFile(FilePaths[k1]);
}
} else
if (command == CyberSearch)
{
Search_Str = Search_TextFiled.getString();
int j = Search_CH.getSelectedIndex();
if (j == 0)
{
System.out.println("搜索文本");
SearchL.deleteAll();
SearchS(Res_StrS, Search_Str, 0, Res_StrS.length - 1);
} else
if (j == 1)
{
System.out.println("搜索文件");
詳情:http://xzf.2000y.net/mb/1/ReadNews.asp?NewsID=565283

J. 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的一部分