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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM