比如有以下代碼,字符串中是一個查詢男生、女生人數的 sql
public class Test {
public static void main(String[] args) {
// 查詢男生、女生人數
String sql = "select sex,count(*)" +
"from student" +
"group by sex;";
}
}
如果我想復制出 sql,一般的做法是先復制出以下內容:
"select sex,count(*)" +
"from student" +
"group by sex;"
然后再刪除雙引號和加號,得到需要的內容
select sex,count(*) from student group by sex;
這樣做比較麻煩,使用 idea 有更簡便的方法
技巧
將光標置於字符串的值處,然后按Alt + Enter(Mac 是 option + return) ,選擇 Copy String Concatenation Text to the Clipboard
復制結果如下,它會刪除所有的 "
和+
,注意它不會將其放在1行上,還是會有3行,但已經很方便了。
select sex,count(*)
from student
group by sex;