/*******************************************************************************
* @Description string operation class
* @Author CManLH@163.com
* @Date 2008/05/24
******************************************************************************/
public class Stringx {
/*
* @Function obtains the maximum length from the specified string a substring of the inverted string
* @Parm str string source string
* @Return has the largest substring of the inverted string, and when there are multiple, only the rightmost one is returned
*/
public string getmaxlenreversestring (String str) {
int startIndex =-1;
int lenofreversestr = 2;
int tmp =-1;
for (int i = Lenofreversestr i <= str.length (); i++) {
tmp = getposofreversestring (str, i);
if (TMP!=-1) {
lenofreversestr = i;
StartIndex = tmp;
str = str.substring (0, tmp + LENOFREVERSESTR);
} else {
break;
}
}
return StartIndex = = 1? Str.substring (0,1): str.substring (Startindex,startindex + lenofreversestr);
}
/*
* @Function from the specified string, gets the starting position of the substring with its reverse string at the rightmost specific length
* @Parm str string source string from which to get the substring of the inverted string
* @Parm Lenofreversestr int Reverses the length of the string
* @Return Int has the starting position of the substring of the inverted string. Returns-1
if no substring inversion string or parameter error exists
*/
public int getposofreversestring (String str, int lenofreversestr) {
if (Lenofreversestr > str.length () | | Lenofreversestr < 1) {
return-1;
}
for (int i = Str.length ()-lenofreversestr i >= 0; i--) {
if (Str.indexof (getreversestring (STR,I,LENOFREVERSESTR))!=-1) {
return i;
}
}
return-1;
}
/*
* @Function to get the inverted string of its substring from the specified string
* @Parm str string source string from which to get the inverted string
* @Parm s int will be reversed to the starting position of the substring in the source string
* @Parm Len Int will be reversed by the length of the substring
* @Return String that was reversed after string. Returns an empty string, such as a parameter error
*/
Public String getreversestring (string str, int s, int len) {
int tmp = s + len;
if (tmp > str.length () | | tmp < 1 | | s * Len < 0) {
return "";
}
StringBuilder reversestr = new StringBuilder (len);
for (int i = s + len-1; I >= s; i--) {
Reversestr.append (Str.charat (i));
}
return reversestr.tostring ();
}
public static void Main (string[] args) {
stringx objtest = new Stringx ();
System.out.println (objtest.getmaxlenreversestring ("Arstuvywfdevutsrz"));
System.out.println (objtest.getmaxlenreversestring ("ABC"));
System.out.println (objtest.getmaxlenreversestring ("Defdedjh"));
System.out.println (objtest.getmaxlenreversestring ("Hijklkjih"));
}
}