vb.net 从字符串中删除双引号

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21690242/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 17:25:12  来源:igfitidea点击:

Removing the double quotes from a string

vb.net

提问by elvinguitar

I have a variable imagesthat is a String. The value of the imagesare in this format: "['C:\Users\Elvin Gentiles\Desktop\RiceLAB\BLB01.JPG';'C:\Users\Elvin Gentiles\Desktop\RiceLAB\BLB02.JPG']"

我有images一个字符串变量。的值采用images以下格式: "['C:\Users\Elvin Gentiles\Desktop\RiceLAB\BLB01.JPG';'C:\Users\Elvin Gentiles\Desktop\RiceLAB\BLB02.JPG']"

How can I convert the value of the imagesto something without the double quotes in the beginning and ending (or should I change the String into some other types of variables? The format that I want is this:

如何将 the 的值转换为images开头和结尾不带双引号的值(或者我应该将 String 更改为其他类型的变量?我想要的格式是这样的:

['C:\Users\Elvin Gentiles\Desktop\RiceLAB\BLB01.JPG';'C:\Users\Elvin Gentiles\Desktop\RiceLAB\BLB02.JPG']

['C:\Users\Elvin Gentiles\Desktop\RiceLAB\BLB01.JPG';'C:\Users\Elvin Gentiles\Desktop\RiceLAB\BLB02.JPG']

No double quotes

没有双引号

Thanks

谢谢

回答by Zafar

The String class has a Replacemethod that will do that.

String 类有一个Replace方法可以做到这一点。

Dim clean as String
clean = images.Replace("""", "")

回答by chris_techno25

Try this...

尝试这个...

Dim s as String = "['C:\Users\Elvin Gentiles\Desktop\RiceLAB\BLB01.JPG';'C:\Users\Elvin Gentiles\Desktop\RiceLAB\BLB02.JPG']"
s = s.Replace("'", "").Trim()

Any character or word or phrase or even a sentence is considered a string when it's enclosed in double quotes, but if the value of your string literally has double quotes, like this "SAMPLE", and you want to remove the double quotes, then do something...

任何字符或单词或短语甚至句子在被双引号括起来时都被视为字符串,但是如果字符串的值字面上有双引号,例如“SAMPLE”,并且您想删除双引号,则执行某物...

Dim s as String = ""['C:\Users\Elvin Gentiles\Desktop\RiceLAB\BLB01.JPG';'C:\Users\Elvin Gentiles\Desktop\RiceLAB\BLB02.JPG']""
s = s.Replace("""", "").Trim()

Yes I noticed...double double quotes...I equated s to something that you say is passed from MATLAB, the string literally has double quotes, so to remove this, you replace double double quotes with nothing. That's how you do it in .NET. Your compiler interprets double double quotes as just a single quote :)

是的,我注意到...双双引号...我将 s 等同于您所说的从 MATLAB 传递的内容,字符串字面上有双引号,因此要删除它,您将双双引号替换为空。这就是您在 .NET 中的做法。您的编译器将双双引号解释为单引号 :)

回答by Gary

Based on the OP's comments I think there is some confusion. Maybe you are new to .Net, coming from MATLAB. To re-iterate in VB or C# .Net this is an Empty string: "" that is a string with length == 0. That is something distinct from a string with the value of a quote or double quote.

根据 OP 的评论,我认为存在一些混淆。也许您是来自 MATLAB 的 .Net 新手。要在 VB 或 C# .Net 中重新迭代,这是一个空字符串: "" 这是一个长度 == 0 的字符串。这与具有引号或双引号值的字符串不同。

To continue:

接着说:

Dim singleQuoteString As String = "'"
Dim doubleQuoteString As String = """"

and so, what you are asking for

所以,你要的是什么

['C:\Users\Elvin Gentiles\Desktop\RiceLAB\BLB01.JPG';'C:\Users\Elvin Gentiles\Desktop\RiceLAB\BLB02.JPG']

is not a string.

不是字符串。

Now, if you want a Textbox, , console output, or something else to show that value then just take your string, like

现在,如果您想要一个文本框、控制台输出或其他内容来显示该值,那么只需使用您的字符串,例如

Dim listOfImagesAsAString = "['C:\Users\Elvin Gentiles\Desktop\RiceLAB\BLB01.JPG';'C:\Users\Elvin Gentiles\Desktop\RiceLAB\BLB02.JPG']"

and assign it to where you want it, like

并将其分配到您想要的位置,例如

Console.Write(listOfImagesAsAString)

then the command prompt will show what you are asking for.

然后命令提示符将显示您的要求。