VB.Net 损坏的字符串 - IDE 错误地将字符串解释为代码 [英] VB.Net corrupted strings - IDE Incorrectly interpreting a string as code

查看:29
本文介绍了VB.Net 损坏的字符串 - IDE 错误地将字符串解释为代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天我打开了一个visual basic项目,其中有几行声明了一些字符串,其中包含逗号分隔的数据.我修改了其中一个字符串,重建并关闭了项目.当我来测试时,出现了错误.当我查看代码时,我发现我修改后的行中的字符串也发生了变化——它们在逗号后插入了空格.

Today I opened a visual basic project which has several lines that declare some strings, which contain comma separated data. I amended one of the strings, rebuilt and closed the project. When I came to test it, there was an error. When I looked at the code, I discovered that the strings on lines after the one I had amended had also changed - they had spaces inserted after the commas.

是否有人在 Visual Studio 2015 中看到 IDE 应用格式错误的正常字符串?

Has anyone seen normal strings incorrectly having formatting applied by the IDE in visual studio 2015?

似乎字符串被格式化为代码.我怀疑这与字符串插值有关,尽管这些是不使用它的遗留项目.

It seems like the string is being formatted as if it were code. I would suspect this has something to do with String Interpolation, though these are legacy projects that do not use it.

编辑,FWIW 代码与此类似,我已重命名字段和标题以尽量保持简短.

Edit, FWIW the code is similar to this, I've renamed the fields and headings to try keep it short.

fullColumnMappingsBuilder.Append(",field1,field2,field3,field4,field5,field6,field7,field8,field9,field10")
fullColumnHeadingsBuilder.Append(",heading1,heading2,heading3,heading4,heading5,heading6,heading7,heading8,heading9,heading10")
If clientCode = "ML" Then
   fullColumnMappingsBuilder.Append(",mlField")
   fullColumnHeadingsBuilder.Append(",mlHeading")
End If
defaultColumnMappingsBuilder.Append(",morefields1,morefields2,morefields3,morefields4")
defaultColumnHeadingsBuilder.Append(",moreHeadings1,moreHeadings2,moreHeadings3,moreHeadings4")

我的编辑是简单地添加 field11 和 Heading11,然后保存.但代码最终看起来像这样:

My edit was to simply add in field11 and heading11, and save. But the code ended up looking like this:

fullColumnMappingsBuilder.Append(",field1,field2,field3,field4,field5,field6,field7,field8,field9,field10,field11")
fullColumnHeadingsBuilder.Append(",heading1,heading2,heading3,heading4,heading5,heading6,heading7,heading8,heading9,heading10,heading11")
    If clientCode = "ML" Then
       fullColumnMappingsBuilder.Append(", mlField")
       fullColumnHeadingsBuilder.Append(", mlHeading")
    End If
defaultColumnMappingsBuilder.Append(", morefields1, morefields2, morefields3, morefields4")
defaultColumnHeadingsBuilder.Append(", moreHeadings1, moreHeadings2, moreHeadings3, moreHeadings4")

问题是IDE在我没有编辑的行上的逗号之后插入了空格.

The problem is that the IDE has inserted spaces after the commas on lines that I did not edit.

推荐答案

好吧,我想我知道我是怎么做到的.如果你从这样的事情开始:

Well, I think I know how I did it. If you start with something like this:

Public Class Class1
  Sub New()
    Dim string1 As String = "Hello there world asdfj asldfkja sad "
    Dim string2 As String = "some code like words dim private as object sub"
  End Sub
End Class

我想我一定是从 string1 的声明中去掉了第一个双引号字符,然后将文本光标的位置移到了不同​​的行.在早期版本的 Visual Studio 中,IDE 会将第一行标记为错误.

I think I must have taken the first double quotes character off the declaration of string1, and then moved the position of the text cursor to a different line. In previous versions of visual studio, the IDE would have marked the first line as being in error.

现在我们有了多行字符串,它认为你有一个多行字符串,从第一行末尾的引号到 string2 As String",并且下面的文本是代码,因此它会发生变化(在这种情况下,关键字大写).

Now we have multi-line strings, it thinks you have a multi-line string running from the quotes at the end of the first line up to string2 As String", and that the following text is code, and so it gets changed (in this case the keywords are capitalized).

 Dim string2 As String = "some code Like words Dim Private As Object Sub"

我在编辑字符串时必须更加小心.

I'll just have to be more careful when editing strings.

这篇关于VB.Net 损坏的字符串 - IDE 错误地将字符串解释为代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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