空间分隔符 [英] Space delimiter

查看:81
本文介绍了空间分隔符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我对vb.net感到愤怒的一件事是

花时间试图让程序做点什么然后

发现已经有了建造程序,

完全相同。


所以在我开始这个之前,任何人都可以告诉我是否有

已经成为这样做的例行程序:


我正在使用

string.split划分分隔的文本字符串。分隔符是一个空格,但

其中有相邻的空格我想将它们视为

单个分隔符。有什么聪明的方法呢?


感谢任何想法

解决方案

yust a thought

strNew = strOld.replace("","")

如果要替换3,4,可以将它放入下一个循环中。 ..空格2

eric


" simonc" <一个******* @ discussions.microsoft.com>在留言中写道

news:0d **************************** @ phx.gbl ... < blockquote class =post_quotes>让我对vb.net感到愤怒的一个原因是花时间试图让程序做一些事情然后发现已经有一个内置程序<完全相同的事情。

所以在我开始之前,任何人都可以告诉我是否已经有例行程序这样做:

我使用
string.split分隔分隔的文本字符串。分隔符是一个空格,但是在那里有相邻的空格我想把它们视为
单个分隔符。这样做的聪明方法是什么?

感谢任何想法



您好Simonc


除了Eric我用stringbuilder制作它,

你问了一些新的东西,这是一个真正快得多的新功能

比所有旧字符串替换功能。但我不知道是否有更好的方式。


Dim a As String =这里有很多空气 ;

Dim sb As New System.Text.StringBuilder(a)

Do while sb.ToString.IndexOf("")> -1''2个空格

sb.Replace("","")

循环

Dim b As String = sb.ToString

Dim c()As String = Split(b)

我希望这有点帮助吗?


Cor

" simonc" <一个******* @ discussions.microsoft.com> schreef in bericht

新闻:0d **************************** @ phx.gbl ... < blockquote class =post_quotes>让我对vb.net感到愤怒的一个原因是花时间试图让程序做一些事情然后发现已经有一个内置程序<完全相同的事情。

所以在我开始之前,任何人都可以告诉我是否已经有例行程序这样做:

我使用
string.split分隔分隔的文本字符串。分隔符是一个空格,但是在那里有相邻的空格我想把它们视为
单个分隔符。有什么聪明的方法呢?

感谢任何想法



2003年11月5日星期三04:27: 09 - 0800,simonc写道:


我正在使用
string.split划分分隔的文本字符串。分隔符是一个空格,但是在那里有相邻的空格我想把它们视为
单个分隔符。有什么聪明的方法呢?




另一种方法是使用正则表达式。这个表达式用一个空格替换所有出现2个或更多空格的




导入System.Text.RegularExpressions


strNew = Regex.Replace(strOld," {2,}","")


-

Chris


要给我发电子邮件,请从我的电子邮件中删除下划线和午餐肉

地址。


One of the things that drives me mad about vb.net is
spending time trying to make a program do something then
finding that there''s already an inbuild procedure that
does exactly the same thing.

So before I begin on this can anyone tell me if there is
already a routine to do this:

I am dividing up a delimited textstring using
string.split. The delimiter character is a space, but
where there are adjacent spaces I want to treat these as a
single delimiter. What is the smart way to do this?

Grateful for any ideas

解决方案

yust a thought
strNew = strOld.replace(" "," ")
you could put it in a for next loop if you want to replace 3,4,... spaces 2

eric

"simonc" <an*******@discussions.microsoft.com> wrote in message
news:0d****************************@phx.gbl...

One of the things that drives me mad about vb.net is
spending time trying to make a program do something then
finding that there''s already an inbuild procedure that
does exactly the same thing.

So before I begin on this can anyone tell me if there is
already a routine to do this:

I am dividing up a delimited textstring using
string.split. The delimiter character is a space, but
where there are adjacent spaces I want to treat these as a
single delimiter. What is the smart way to do this?

Grateful for any ideas



Hi Simonc

In addition to Eric did I make it with stringbuilder,
you asked something new and this is a new function who is real much faster
than all old string replace funtions. But I don''t know if there is not a
better way.

Dim a As String = "There is a lot of for air here"
Dim sb As New System.Text.StringBuilder(a)
Do While sb.ToString.IndexOf(" ") > -1 ''2 spaces
sb.Replace(" ", " ")
Loop
Dim b As String = sb.ToString
Dim c() As String = Split(b)
I hope this helps a little bit?

Cor
"simonc" <an*******@discussions.microsoft.com> schreef in bericht
news:0d****************************@phx.gbl...

One of the things that drives me mad about vb.net is
spending time trying to make a program do something then
finding that there''s already an inbuild procedure that
does exactly the same thing.

So before I begin on this can anyone tell me if there is
already a routine to do this:

I am dividing up a delimited textstring using
string.split. The delimiter character is a space, but
where there are adjacent spaces I want to treat these as a
single delimiter. What is the smart way to do this?

Grateful for any ideas



On Wed, 5 Nov 2003 04:27:09 -0800, simonc wrote:


I am dividing up a delimited textstring using
string.split. The delimiter character is a space, but
where there are adjacent spaces I want to treat these as a
single delimiter. What is the smart way to do this?



Yet another method is to use regular expressions. This expression replaces
all occurrences of 2 or more spaces with a single space.

Imports System.Text.RegularExpressions

strNew = Regex.Replace(strOld, " {2,}", " ")

--
Chris

To send me an E-mail, remove the underscores and lunchmeat from my E-Mail
address.


这篇关于空间分隔符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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