我当前的字符串“ Model 1467”要转换为“ 1467_Profile”之后的内容。
之前: Medole 1467
之后: 1467_Profile
答案 0 :(得分:2)
您可以将replaceAll
与正则表达式一起使用:
String str = "Model 1467";
str = str.replaceAll(".*?(\\d+)$", "$1_Profile");
System.out.println(str);
=> 1467_Profile
答案 1 :(得分:1)
假设数字始终在单词后面,
String before = "Model 1467";
String after = before.split("\\s")[1]+"_Profile";
System.out.println(after);