在编辑器中将多行代码分布在多行上,以便于阅读 [英] Spread long line of code over multiple lines in the editor to make it easier to read

查看:99
本文介绍了在编辑器中将多行代码分布在多行上,以便于阅读的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有一长串代码用于字符串格式,并且想知道如何将它传播到多行,所以它是在编辑器界面中更容易阅读?



  const  字符串 format =   {0,3} | {1,6} | A {2,6} | B {3,4} | C {4,4} | D {5,4} | E {6,4} | F {7,4} | G {8,3} | H {9,4} | I {10,4} | J {11,3} | K {12,2} | L {13,2} | M {14,6} | N {15,6} | O {16,6} | P {17,6} | Q {18,1} | R {19,4} | S {20,2} | T {21,4} | U {22,4} | V { 23,3} | W {24,8}; 





感谢帮助,

suprsnipes

解决方案

如果你不想要任何嵌入的行尾字符,那么@...语法就不会有帮助。

但是,你可以使用连接运算符(+):

  const   string  format =   {0,3} | {1,6} | A {2,6} | B {3,4} | C {4,4} | D {5,4} | E {6,4} + 
| F {7,4} | G {8,3} | H {9,4} | I {10 ,4} | J {11,3} | K {12,2} +
| L {13,2} | M {14,6} | N {15,6} | O {16,6} | P {17,6} | Q {18,1} +
| R {19,4} | S {20,2} | T {21,4} | U {22,4} | V {23,3} | W {24,8};


代码不好,代码的格式化没有帮助。但是有些原因,你展示了这些日子里非常糟糕的两种趋势:尝试使用表示数据而不是数据本身的字符串,以及硬编码。这很难治愈。



关于你的问题,多行字符串文字可以用详细形式写成,当你用''@作为前缀时'':

 < span class =code-keyword> const   string  format =  @ 从这里开始
继续
继续...
...
依旧...
end
;





在你的情况下,它没什么意义。



阅读写作之前的语言手册谁知道什么。你现在正在修改的不是编程。



祝你好运,

-SA

Hi,

I have a long line of code that is for a string format and would like to know how I can spread it over multiple lines so it is easier to read in the editor screen?

const string format = "{0,3} | {1,6} |A {2,6} |B {3,4} |C {4,4} |D {5,4} |E {6,4} |F {7,4} |G {8,3} |H {9,4} |I {10,4} |J {11,3} |K {12,2} |L {13,2} |M {14,6} |N {15,6} |O {16,6} |P {17,6} |Q {18,1} |R {19,4} |S {20,2} |T {21,4} |U {22,4} |V {23,3} |W {24,8}";



Appreciate the help,
suprsnipes

解决方案

If you don''t want any embedded end-of-line characters, then the @"..." syntax won''t help.
But, you can use the concatenation operator (+):

const string format = "{0,3} | {1,6} |A {2,6} |B {3,4} |C {4,4} |D {5,4} |E {6,4}" + 
                      " |F {7,4} |G {8,3} |H {9,4} |I {10,4} |J {11,3} |K {12,2}" + 
                      " |L {13,2} |M {14,6} |N {15,6} |O {16,6} |P {17,6} |Q {18,1}" + 
                      " |R {19,4} |S {20,2} |T {21,4} |U {22,4} |V {23,3} |W {24,8}";


It the code is bad, formatting of the code won''t help. But some reason, you demonstrate two of the trends haunting beginners very badly these days: trying to work with strings representing data instead of data itself, and hard-coding. This is very hard to cure.

As to your question, multi-line string literal can be written in verbose form, when you prefix it with ''@'':

const string format = @"begin here
continue
continue...
...
and so on...
end";



In your case, it makes very little sense.

Read the language manual before writing who knows what. What you are righting right now is not programming at all.

Wish you the best of luck,

—SA


这篇关于在编辑器中将多行代码分布在多行上,以便于阅读的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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