Removes all occurrences of characters in a string

    String a="123444344";
        //12444
        a=a.replaceAll("34","");
Copy the code

Deletes data from a string with a specified subscript interval

StringTest = ("test123test123");test = test.substring(5.12); 
Copy the code

The results of

test = 23test1
Copy the code

Before or after intercepting a character (can be a string)

        String str = "123? 456"; / / intercept? Previous string123
          str.substring(0, str.indexOf("?")); / / intercept? Subsequent string456
        String str1=str.substring(0, str.indexOf("?"));
        String str2=str.substring(str1.length()+1, str.length());
Copy the code

Intercept by subscript

System. The out. Println (a.s ubstring (0, 3));Copy the code



Intercepts the value between two strings

Public static String subString(String STR, String strStart, StrStartIndex = str.indexof (strStart); /* strEnd = str.indexof (strStart); int strEndIndex = str.indexOf(strEnd); */ if (strStartIndex < 0) {return "string :---->" + STR + "<----" + strStart + "does not exist, Unable to intercept target string "; } the if (strEndIndex < 0) {return "string: -- -- -- -- >" + STR + "< -- there is no" + strEnd + ", unable to intercept target string "; } /* start to pick */ String result = str.subString (strStartIndex, strEndIndex).substring(strstart.length ()); return result; }Copy the code

Gets the index of the occurrence of a symbol

    public static void main(String[] args) {
        String a="123456789";
        System.out.println(getIndex(a,2.","));

    }   //test = test.replace("chaoji"."");
    public static int getIndex(String string, int i, StringSTR) {// here is the fetch"/"The subscript of the third occurrence of the symbol //Matcher slashMatcher = Pattern.compile("/").matcher(string);
        Matcher slashMatcher = Pattern.compile(str).matcher(string);
        int mIdx = 0; while (slashMatcher.find()) { mIdx++; / / when"/"The position of the symbol's third occurrenceif (mIdx == i) {
                break;
            }
        }
        return slashMatcher.start();
    }
Copy the code

The results of

7
Copy the code

Gets the last occurrence of a symbol

String STR = "1, 2, 3,"; // Get the subscript value of the last track number, starting at 0. int lastIndexOf = str.lastIndexOf(","); // Result: 5Copy the code

String is converted to list based on delimiters

        String a="123456789, ABC def";


        List<String> idList = Arrays.asList(a.split(","));
        System.out.println("idList = " + idList);
Copy the code

The results of

idList = [123.456.789, abc, def]
Copy the code

Intercepts the numeric portion of a string

		char[]chs="hycx525xx123".toCharArray();
		String userorderno="";
		for (int i = 0; i < chs.length; i++) {
			if(chs[i]>=48&&chs[i]<=57){
				userorderno=userorderno+String.valueOf(chs[i]);
			}
		}
		//525123
		System.out.println(userorderno);
Copy the code