IntelliJ IDEA使用技巧,複製字符串連接文本到剪切板

比如有以下代碼,字符串中是一個查詢男生、女生人數的 sql

public class Test {

    public static void main(String[] args) {
        // 查詢男生、女生人數
        String sql = "select sex,count(*)" +
                "from student" +
                "group by sex;";
    }

}

image.png

如果我想複製出 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

image.png

複製結果如下,它會刪除所有的 "+ ,注意它不會將其放在1行上,還是會有3行,但已經很方便了。

select sex,count(*)
from student
group by sex;

參考

Copying a concatenated constant to the clipboard

串接(Concatenation)- wikipedia

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章