将字符串数组复制到字符串 [英] Copy string array to string
问题描述
是否有更快的方法将字符串的ArrayList复制到除了
a紧环之外的字符串。
这是最简单的术语,我现在正在使用这样的东西...
------------------------- ---
***注意:rtbXML是表格上的富文本框
dim iCntr为整数
dim sText as string
dim arList as new ArrayList
''这里的代码将构建一个非常大的Rich Text Box字符串。
arList.Add(" String 1")
arList.Add(" String 2")
arList.Add(" String 3" )
''我想用更快的东西替换下面的循环
sText =""
for iCntr = 0 to arList.Count - 1
sText + = arList.Item(iCntr)
next
rtbXML。 Rtb = sText
-----------------------------
我正在构建字符串转到Rich Test Box,例如rtbXML.rtb =
stext。我最初将RTB格式的行添加到ArrayList
,因为在小块中将格式添加到''stext''变量需要一个
looooong时间。我的想法是拥有一个非常快速的memcpy,以便尽快让sraxt获得arraylist
。我真正想要的是直接从arraylist转到rtbXML.Rtb
,但我会满足于快速memcpy。
实际上,我真正想要的是能够在我的表单上的.NET浏览器框中显示我的XML文本
文件。我使用ActiveX浏览器
控件来显示XML文件。但是,这意味着我必须在客户计算机上为浏览器安装
ActiveX dll。这并不是那么糟糕,
但是长话短说,我的客户拥有他们的b
电脑的环境并没有让它真正易于安装所有额外的司机。所以,我的b $ b决定编写我自己的XML查看器,但是我需要加速
RTB部分。
感谢您的帮助,
Brian
我认为使用Stringbuilder类假设比仅仅更快
String类。我没有证据支持我,就像我在这个新闻组中读到的那样。有人纠正我,如果我今天早上还没有足够的恩惠,而且我没有想清楚。
另外,我想知道是否将字符串
直接分配给循环中的rtbXML.Rtb对象会更快。我不知道的两件事
关于它我的头脑。当rtbXML.Rtb = sText运行它是否有
将字符串复制到Rtb,后者在内存中生成两个副本,如果你
做了rtbXML.Rtb + = arList .Item(iCntr)如果rtbXML对象对该对象进行额外的处理,则会降低成本效率。
Chris
" DumberThanSnot" <都************ @ nospam.com>在消息中写道
新闻:uy ************** @ TK2MSFTNGP12.phx.gbl ...有没有更快的方法将字符串的ArrayList复制到其他字符串而不是紧密循环。
用最简单的术语来说,我现在正在使用这样的东西...
----------------------------
***注意:rtbXML是一个表单上的富文本框
dim iCntr为整数
dim sText as string
dim arList as new ArrayList
''这里的代码将构建一个非常大的Rich Text Box字符串。
arList.Add(" String 1")
arList.Add(" String 2")
arList.Add(" String 3")
''我想用更快的东西替换下面的循环
sText =""
对于iCntr = 0到arList.Count - 1 > sText + = arList.Item(iCntr)
下一页
rtbXML.Rtb = sText
-------------- ---------------
我正在构建stri转到Rich Test Box,例如rtbXML.rtb
= stext。我最初将RTB格式的行添加到ArrayList
,因为在小块中将格式添加到''stext''变量需要花费很长时间。我们的想法是拥有一个非常快速的memcpy,以尽快将
arraylist转换为sText。我真正想要的是直接从arraylist转到rtbXML.Rtb,但我会满足于快速memcpy。
实际上,我真正想要的是能够在我的表单上的.NET浏览器框中显示我的XML文本文件。我使用ActiveX浏览器
控件来显示XML文件。但是,这意味着我必须为客户计算机上的浏览器安装ActiveX dll。这并不是那么糟糕,但长话短说,我的客户拥有他们的电脑的环境并没有让安装所有额外的
驱动程序变得非常容易。所以,我决定编写自己的XML查看器,但是我需要
来加速RTB部分。
感谢您的帮助,
Brian
" DumberThanSnot" <都************ @ nospam.com> schrieb:是否有更快的方法将字符串的ArrayList复制到其他字符串而非紧密循环。
特别是对于编写大文件/字符串,我会使用
''System.Text.StringBuilder'':
\\\
Imports System.Text
..
..
..
Dim sb作为新的StringBuilder()
每个s as String in astr
sb.Append(s)
下一个s
Me.RichTextBox1.Rtf = sb.ToString()
///
-
MS Herfried K. Wagner
MVP< URL:http://dotnet.mvps.org/>
VB< URL:http://dotnet.mvps.org/dotnet / faqs />
Dim al As New ArrayList
al.Add(" ;一个)
al.Add(" Two")
al.Add(" Three")
Dim s As String
s = String.Jo in(",",DirectCast(al.ToArray(GetType(String)),
String()))
BTW,在使用时连接字符串最好使用
StringBuilder类。
HTH,
Sam
On Thu,2005年2月3日07:15:00 -0800,DumberThanSnot
< Du ************ @ nospam。 COM>写道:
有没有更快的方法将字符串的ArrayList复制到一个紧密循环以外的字符串。
在它''最简单的术语,我现在正在使用这样的东西...
------------------------- ---
***注意:rtbXML是一个富文本框,形式为
dim iCntr为整数
dim sText as string
dim arList as new ArrayList
''这里的代码将构建一个非常大的Rich Text Box字符串。
arList.Add(" String 1")
arList.Add(" ; String 2")
arList.Add(" String 3")
''我想用更快的东西替换下面的循环
sText ="
for iCntr = 0 to arList.Count - 1
sText + = arList.Item(iCntr)
下一页
rtbXML.Rtb = sText
is there a faster way to copy an ArrayList of strings to a string other than
a tight loop.
In it''s most simple terms, I''m currently using something like this...
----------------------------
*** NOTE: rtbXML is a Rich Text Box on the form
dim iCntr as integer
dim sText as string
dim arList as new ArrayList
'' Code here will be building a very large Rich Text Box string.
arList.Add("String 1")
arList.Add("String 2")
arList.Add("String 3")
'' I''d like to replace the following loop with something faster
sText = ""
for iCntr = 0 to arList.Count - 1
sText += arList.Item(iCntr)
next
rtbXML.Rtb = sText
-----------------------------
I''m building the string to hand off to a Rich Test Box such as "rtbXML.rtb =
stext". I''m originally adding the lines of RTB formats to the ArrayList
because adding the formats to the ''stext'' variable in small chunks takes a
looooong time. The idea is to have a very fast memcpy to get the arraylist
to sText as quickly as possible. What I would really like is to go directly
from the arraylist to the rtbXML.Rtb, but I''ll settle for a fast "memcpy".
Actually, what I would really like is to be able to display my XML text
files in a .NET browser box on my form. I was using the ActiveX browser
control to display the XML files. but, that meant that I had to install the
ActiveX dll for the browser on my customers computers. That wasn''t so bad,
but to make a long story short, the environment that my customers have their
computers doesn''t make it real easy to install all the extra drivers. So, I
decided to write my own XML viewer which works, but I need to speed up the
RTB section a bit.
thanks for any help,
Brian
I think using Stringbuilder class is suppose to be faster than just the
String class. I don''t have evidence to back that up on me, just what I''ve
been reading in this newsgroups. Someone correct me if I haven''t had enough
caffee yet this morning and I''m not thinking clearly.
Also, I was wondering if it would be faster just to assign the string
directly to the rtbXML.Rtb object in the loop. Two things I don''t know
about it off the top of my head. When rtbXML.Rtb = sText runs does it have
to copy the string over to Rtb which makes two copies in memory, and if you
did rtbXML.Rtb += arList.Item(iCntr) if the rtbXML object does extra
processing on the object which would make it less cost effective.
Chris
"DumberThanSnot" <Du************@nospam.com> wrote in message
news:uy**************@TK2MSFTNGP12.phx.gbl...is there a faster way to copy an ArrayList of strings to a string other
than a tight loop.
In it''s most simple terms, I''m currently using something like this...
----------------------------
*** NOTE: rtbXML is a Rich Text Box on the form
dim iCntr as integer
dim sText as string
dim arList as new ArrayList
'' Code here will be building a very large Rich Text Box string.
arList.Add("String 1")
arList.Add("String 2")
arList.Add("String 3")
'' I''d like to replace the following loop with something faster
sText = ""
for iCntr = 0 to arList.Count - 1
sText += arList.Item(iCntr)
next
rtbXML.Rtb = sText
-----------------------------
I''m building the string to hand off to a Rich Test Box such as "rtbXML.rtb
= stext". I''m originally adding the lines of RTB formats to the ArrayList
because adding the formats to the ''stext'' variable in small chunks takes a
looooong time. The idea is to have a very fast memcpy to get the
arraylist to sText as quickly as possible. What I would really like is to
go directly from the arraylist to the rtbXML.Rtb, but I''ll settle for a
fast "memcpy".
Actually, what I would really like is to be able to display my XML text
files in a .NET browser box on my form. I was using the ActiveX browser
control to display the XML files. but, that meant that I had to install
the ActiveX dll for the browser on my customers computers. That wasn''t so
bad, but to make a long story short, the environment that my customers
have their computers doesn''t make it real easy to install all the extra
drivers. So, I decided to write my own XML viewer which works, but I need
to speed up the RTB section a bit.
thanks for any help,
Brian
"DumberThanSnot" <Du************@nospam.com> schrieb:is there a faster way to copy an ArrayList of strings to a string other
than a tight loop.
Especially for composing large files/strings, I would use a
''System.Text.StringBuilder'':
\\\
Imports System.Text
..
..
..
Dim sb As New StringBuilder()
For Each s As String In astr
sb.Append(s)
Next s
Me.RichTextBox1.Rtf = sb.ToString()
///
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Dim al As New ArrayList
al.Add("One")
al.Add("Two")
al.Add("Three")
Dim s As String
s = String.Join(",", DirectCast(al.ToArray(GetType(String)),
String()))
BTW, when working with concatenating strings it''s better to use the
StringBuilder class.
HTH,
Sam
On Thu, 3 Feb 2005 07:15:00 -0800, "DumberThanSnot"
<Du************@nospam.com> wrote:
is there a faster way to copy an ArrayList of strings to a string other than
a tight loop.
In it''s most simple terms, I''m currently using something like this...
----------------------------
*** NOTE: rtbXML is a Rich Text Box on the form
dim iCntr as integer
dim sText as string
dim arList as new ArrayList
'' Code here will be building a very large Rich Text Box string.
arList.Add("String 1")
arList.Add("String 2")
arList.Add("String 3")
'' I''d like to replace the following loop with something faster
sText = ""
for iCntr = 0 to arList.Count - 1
sText += arList.Item(iCntr)
next
rtbXML.Rtb = sText
这篇关于将字符串数组复制到字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!