如何自动拆分IntelliJ IDEA中的长字符串? [英] How to split long strings in IntelliJ IDEA automatically?

查看:849
本文介绍了如何自动拆分IntelliJ IDEA中的长字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个包含很长字符串的测试,我需要拆分这些字符串:

I am writing a test with very long strings, and I need to split those strings:

private static final String TOO_LONG_JSON = "{field1:field1, field2:field2 ... fieldN:fieldN}";

所以他们会变成:

private static final String TOO_LONG_JSON = "{field1:field1, field2:field2" + 
    "{field3:field3, field4:field4,field6:field6, field7:field7}" +
    "{field8:field8, field9:field9,field10:field10, field11:field11}" +
    " ... fieldN:fieldN}";

是否可以设置IntelliJ IDEA来自动拆分那些长字符串?

Is it possible to set up IntelliJ IDEA to automatically split those long strings?

推荐答案

您可以使用自动格式化( CTRL + ALT + L ),在代码样式设置中进行了一些更改。

You can use auto-formatting (CTRL + ALT + L), after few changes in Code Style settings.


  • CTRL + ALT + S 打开设置窗口

  • 查找代码样式/ Java部分

  • 确保取消选中换行选项和检查确保不超出右边距选项

  • 按确定接受您所做的更改

  • Press CTRL + ALT + S to open Settings window
  • Find Code Style / Java section
  • Make sure to uncheck "Line Breaks" option and check "Ensure right margin is not exceeded" option
  • Press OK to accept changes you've made

现在使用自动格式化时( CTRL + ALT + L )超过行字符限制的长字符串将自动剪切成多行。

Now when using auto-formatting (CTRL + ALT + L) long strings exceeding line character limit will be automatically cut into multiple lines.

这篇关于如何自动拆分IntelliJ IDEA中的长字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆