Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 将引号内的子字符串与整行分隔开_Vb.net_String_Visual Studio_Replace_Trim - Fatal编程技术网

Vb.net 将引号内的子字符串与整行分隔开

Vb.net 将引号内的子字符串与整行分隔开,vb.net,string,visual-studio,replace,trim,Vb.net,String,Visual Studio,Replace,Trim,以下是我试图操纵的一条线的示例: trait slot QName(PrivateNamespace("*", "com.company.assembleegameclient.ui:StatusBar"), "_-0IA") type QName(PackageNamespace(""), "Boolean") value False() end 我编写了一个代码,它将遍历和读取每一行,并在适当的行停止。我现在要做的是通读这些字符,只保存这些字符 _-0IA 到一个新的字符串。到目前为

以下是我试图操纵的一条线的示例:

  trait slot QName(PrivateNamespace("*", "com.company.assembleegameclient.ui:StatusBar"), "_-0IA") type QName(PackageNamespace(""), "Boolean") value False() end
我编写了一个代码,它将遍历和读取每一行,并在适当的行停止。我现在要做的是通读这些字符,只保存这些字符

_-0IA

到一个新的字符串。到目前为止,我尝试使用Trim()、Replace()和indexof,但由于引号的缘故,我遇到了很多困难。以前有人处理过这个问题吗?

假设您的源字符串始终遵循严格的格式,只有一些数据更改,类似这样的操作可能会奏效:

    'Split the string by "," and extract the 3rd element.  Trim the space and _
     quotation mark from the front and extract the first 5 characters.
    Dim targetstr As String = sourcestr.Split(","c)(2).TrimStart(" """.ToCharArray).Substring(0, 5)
如果目标字符串的长度是可变的,可以这样做:

    Dim temp As String = teststr.Split(","c)(2).TrimStart(" """.ToCharArray)
    'Use the index of the next quotation mark instead of a fixed length
    Dim targetstr As String = temp.Substring(0, temp.IndexOf(""""c))

谢谢你的帮助。我会玩弄你的想法,看看我能做些什么。我不知道你可以用那种方式来使用split。你能解释一下最后一个字符串末尾的c是什么意思吗?
c
是VB表示文字字符的方式。因为引号是VB表示字符串文字的方式,所以需要将它加倍来转义