Home > Back-end >  Good pain, who will save me!!!!!!!
Good pain, who will save me!!!!!!!

Time:09-17

Write a the find function
Parameters: the String STR, String the begin, String end;
Role: STR string in all begin with the begin and end with the end of the string
Output is: the String []

For example: [110011] 0 a0b0c [0001] of the query result there should be two strings: 110011, and 0001

CodePudding user response:

Public static void found (String STR, String the begin, the String end) {

int a=0;
Int b=0;
Int c=0;
List List=new ArrayList<& gt; (a);
While (StringUtils. IsNotBlank (STR)) {

A=STR. IndexOf (begin) + 1;
B=STR. IndexOf (end);
If (bSTR=STR. The substring (a - 1);
A=STR. IndexOf (begin) + 1;
B=STR. IndexOf (end);
}
String substring=STR. The substring (a, b);
List. The add (substring);
STR=STR. The substring (b + 1);
}
System.out.println(list);
}

CodePudding user response:

String STR []={" sadd ", "fasdf", "dddass"};
for(int i=0; IIf (STR [I] startsWith (" dd ") & amp; & STR [I] endsWith (" s ")) {
System. The out. Println (STR [I]);
}
}
The basic ideas, specific oneself confidence

CodePudding user response:

Public static String [] get String (String STR, String the begin, the String end) {
The Pattern p=Pattern.com running (the begin + ". * "+ end);
The Matcher m=p. atcher (STR);
If (m. ind ()) {
Return a new String [] {begin and end};
}
Return null;
}
Only to arrive at the begin and end? A bit of a mystery

CodePudding user response:

Public static String find (String STR, String the begin, the String end) {
If (STR. ToLowerCase (). The startsWith (begin) & amp; & STR. ToLowerCase (). The endsWith (end)) {
return str;
}
return "";

}

CodePudding user response:

CodePudding user response:

I wrote a way of considering situations, you can refer to https://blog.csdn.net/WORDHERO001/article/details/108644966

CodePudding user response:

The
refer to the original poster SJJ_ hey ha response:

write a find functionParameters: the String STR, String the begin, String end;
Role: STR string in all begin with the begin and end with the end of the string
Output is: the String []

For example: [110011] 0 a0b0c [0001] of the query result there should be two strings: 110011, and 0001



You don't begin and end, who know how to draw the result is!

CodePudding user response:

 import Java. Util. Regex. Matcher. 
import java.util.regex.Pattern;

/* *
* @ description x
* @ author: Tany
* @ E-mail: 5824519 @qq.com
* @ createDate: 2020/9/17
* @ version: 1.0.0
*/
Public class T {
Public static final Pattern p=Pattern.com running (" \ \ [(. *?) \ \] ");

Public static void main (String [] args) {
String STR="FSDFDS [110011] 0 a0b0c [0001] 0 a0b0c [0001] 0 a0b0c [0001] 0 a0b0c [0001] FDSFSDF";
The Matcher m=p. atcher (STR);
While (m. ind ()) {
System. The out. Println (m.g roup (1));
}
}
}
  • Related