data.Split(vbCrLf)的问题 [英] problem with data.Split(vbCrLf)

查看:255
本文介绍了data.Split(vbCrLf)的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


我正在尝试解析换行符上的字符串。我认为vbCrLf是一个字符串常量。如何在换行符char上解析我的

字符串 - 数据?

....

data + = ASCII.GetString(buffer ,0,bytesRead)

....

Dim parts()As String = data.Split(vbCrLf)


谢谢,

Ron

解决方案

嗨罗恩,


我认为字符串对象的拆分方法可以使用单个字符或

一个字符数组。如果你使用后者的重载,.NET将假设

数组中的任何字符都有资格作为分隔字符,因此如果你传递给CrLf,它决定了Cr OR Lf是一个分隔符。这意味着

你将得到一个空白字符串,用于

parts()数组中的每个其他元素。


我一直使用的方式是很好的'''''''''''''''''''''''''''''''''''''''''''''''''''''''''$ $ $ $ $ $ $ $ b b b b b b b b b b ()As String = Split(data,vbCrLf)


问候,

Alex Clark

" Ron" <一个******* @ discussions.microsoft.com>在消息中写道

news:17 **************************** @ phx.gbl ... < blockquote class =post_quotes>你好,

我试图在换行符char上解析一个字符串。我猜测vbCrLf是一个字符串常量。如何在换行符char上解析我的
字符串 - 数据?
数据+ = ASCII.GetString(缓冲区,0,bytesRead)
...
Dim parts()As String = data.Split(vbCrLf)

谢谢,
Ron



您可以使用StringReader逐行读取字符串:


Dim sr作为新的StringReader(sStringToRead)

而sr.peek<> -1

Dim s as string = sr.ReadLine

''用s做点什么

end


也许这会对你有所帮助


谢谢。我想到了,但我想我会检查

,看看我是否在vb.net中遗漏了一些东西。猜猜

我必须导入Microsoft.VisualBasice命名空间吗?


再次感谢,

Ron

-----原始消息-----
嗨罗恩,

我认为字符串对象的Split方法要么是
采用单个字符或字符数组。如果你使用后者的重载,.NET
将假设数组中的任何字符都有资格作为分隔
字符,因此如果你传入CrLf它决定Cr或Lf是
分隔器。这意味着你最终将为parts()数组中的每个其他元素
添加一个空白字符串。

我总是使用的方式是好的'''''''''''''''''''''''''''''''''''''''' $ b函数,因为这正是你想要的,例如:

Dim parts()As String = Split(data,vbCrLf)

问候,
Alex Clark

" Ron" <一个******* @ discussions.microsoft.com>写在
messagenews:17 **************************** @ phx.gbl ...

您好,

我正在尝试解析换行符上的字符串。我猜测vbCrLf是一个字符串常量。如何在换行符char上解析我的
字符串 - 数据?
数据+ = ASCII.GetString(缓冲区,0,bytesRead)
...
Dim parts()As String = data.Split(vbCrLf)

谢谢,
Ron





Hello,

I am trying to parse a string on the newline char. I
guess vbCrLf is a string constant. How can I parse my
string - data - on the newline char?
....
data += ASCII.GetString(buffer, 0, bytesRead)
....
Dim parts() As String = data.Split(vbCrLf)

Thanks,
Ron

解决方案

Hi Ron,

I think the Split method of the string object either takes a single char or
an array of chars. If you use the latter overload, .NET will assume that
any of the chars in the array qualify as a separating character, hence if
you pass in CrLf it decides that either Cr OR Lf is a separator. This means
you''ll end up with a blank string for every other element in the array of
parts().

The way I always use is the good ol'' fashioned VB Split function, as this
does exactly what you want, eg:

Dim parts() As String = Split(data, vbCrLf)

Regards,
Alex Clark
"Ron" <an*******@discussions.microsoft.com> wrote in message
news:17****************************@phx.gbl...

Hello,

I am trying to parse a string on the newline char. I
guess vbCrLf is a string constant. How can I parse my
string - data - on the newline char?
...
data += ASCII.GetString(buffer, 0, bytesRead)
...
Dim parts() As String = data.Split(vbCrLf)

Thanks,
Ron



You can use a StringReader to read a string line by line:

Dim sr As new StringReader(sStringToRead)
while sr.peek <> -1
Dim s as string = sr.ReadLine
''Do something with s here
end While

Perhaps this will help you


Thanks. I thought about that, but I thought I would check
to see if maybe I was missing something in vb.net. Guess
I have to import the Microsoft.VisualBasice namespace?

Thanks again,
Ron

-----Original Message-----
Hi Ron,

I think the Split method of the string object either takes a single char oran array of chars. If you use the latter overload, .NET will assume thatany of the chars in the array qualify as a separating character, hence ifyou pass in CrLf it decides that either Cr OR Lf is a separator. This meansyou''ll end up with a blank string for every other element in the array ofparts().

The way I always use is the good ol'' fashioned VB Split function, as thisdoes exactly what you want, eg:

Dim parts() As String = Split(data, vbCrLf)

Regards,
Alex Clark
"Ron" <an*******@discussions.microsoft.com> wrote in messagenews:17****************************@phx.gbl...

Hello,

I am trying to parse a string on the newline char. I
guess vbCrLf is a string constant. How can I parse my
string - data - on the newline char?
...
data += ASCII.GetString(buffer, 0, bytesRead)
...
Dim parts() As String = data.Split(vbCrLf)

Thanks,
Ron


.



这篇关于data.Split(vbCrLf)的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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