繁体   English   中英

IntelliJ - 是否可以将String.format或StringBuilder的输出复制到剪贴板中?

[英]IntelliJ - is it possible to copy an output of String.format or StringBuilder into clipboard?

根据以下问题和回答:

如何在不运行代码的情况下找到Intellij Idea中的静态字符串结果连接?

可以将IntelliJ的字符串连接结果复制到剪贴板中。

让我引用一下:

 just put cursor on the string concatenation Press alt + enter Select "Copy String concatenation text into clipboard" Paste result somewhere. 

但是,我发现这个解决方案在String.format的情况下不起作用。

IntelliJ是否有允许执行此操作的变通方法或插件?

public class Main {

    public static void main(String[] args) {
        final String one = "want";
        final String two = "copy";
        final String three = "concatenated string";

        // I want to copy whole concatenated string
        String canBeCopiedIntoClipBoard = "I " + one + " to " + two + " whole " + three;
        String cannotCopyResultIntoClipBoard = String.format("I %s to %s whole %s", one, two, three);

        assert canBeCopiedIntoClipBoard.equals(cannotCopyResultIntoClipBoard);
        System.out.println(canBeCopiedIntoClipBoard);
    }
}

它不能直接从IDE做是因为一个简单的事实是,在结果的建筑中使用的变量可以来自任何地方,不得在编译时是已知的,以及无论外部类中调用执行的复杂性(想想可能起作用的环境变量)。

你可以做, 如果你可以运行结果的施工点。

  • 在'cannotCopyResultIntoClipBoard'的行中放置一个断点并开始调试,
  • 选择生成字符串的部分,
  • 开放的“评估”面板(有时Alt + F8,始终运行计算表达式...)
  • 按回车键,
  • 在结果面板中,点击右键, 复制值

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM