Java通过substring截取指定字符
package com.shucha.deveiface.biz.test;
import com.sdy.common.utils.StringUtil;
/**
* @author tqf
* @Description
* @Version 1.0
* @since 2022-05-17 11:14
*/
public class test2 {
public static void main(String[] args) {
String name = "mysql_表名_ddd_2";
System.out.println(tableNameSubString(name));
}
/**
* 表名截取
* @param tableName
* @return
*/
public static String tableNameSubString(String tableName){
String name = "";
if(StringUtil.isNotBlank(tableName)) {
name = tableName.substring(tableName.indexOf("_")+1,
tableName.lastIndexOf("_"));
}
return name;
}
}
截取字符为:表名_ddd