473,795 Members | 2,443 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Copy string array to string

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("Str ing 1")
arList.Add("Str ing 2")
arList.Add("Str ing 3")

' I'd like to replace the following loop with something faster
sText = ""
for iCntr = 0 to arList.Count - 1
sText += arList.Item(iCn tr)
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
Nov 21 '05 #1
12 4928
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(iCn tr) 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******** ******@TK2MSFTN GP12.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("Str ing 1")
arList.Add("Str ing 2")
arList.Add("Str ing 3")

' I'd like to replace the following loop with something faster
sText = ""
for iCntr = 0 to arList.Count - 1
sText += arList.Item(iCn tr)
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

Nov 21 '05 #2
"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.St ringBuilder':

\\\
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/>

Nov 21 '05 #3

Dim al As New ArrayList
al.Add("One")
al.Add("Two")
al.Add("Three")

Dim s As String

s = String.Join("," , DirectCast(al.T oArray(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("St ring 1")
arList.Add("St ring 2")
arList.Add("St ring 3")

' I'd like to replace the following loop with something faster
sText = ""
for iCntr = 0 to arList.Count - 1
sText += arList.Item(iCn tr)
next

rtbXML.Rtb = sText

Nov 21 '05 #4
Hi,

if one have to concat many strings it's the better way to use a
StringBuilder, it' much faster!!!

dim iCntr as integer
dim sText as string
dim arList as new ArrayList

arList.Add("Str ing 1")
arList.Add("Str ing 2")
arList.Add("Str ing 3")

StringBuilder sbText = new StringBuilder()
for iCntr = 0 to arList.Count - 1
sbText.Append(a rList.Item(iCnt r))
next

rtbXML.Rtb = sbText.ToString ()
Possibly if one have a Array of Strings ('String()') one can use String.Join()

Dim arString as String()

....

rtbXML.Rtb = String.Join("", arString)
but I don't now about performance!
Roland

"DumberThanSnot " 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("Str ing 1")
arList.Add("Str ing 2")
arList.Add("Str ing 3")

' I'd like to replace the following loop with something faster
sText = ""
for iCntr = 0 to arList.Count - 1
sText += arList.Item(iCn tr)
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

Nov 21 '05 #5
Addendum:

If you have a string array, you can alternatively use 'Strings.Join' or
'String.Join' to concatenate the strings.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #6
thanks for all the replies... as per your ideas and examples... I replaced
the "string.joi n" method just to get the code running right now. I'm in the
process of converting all the applicable routines to stringbuilder.
unfortunately, I've been used to doing "memory work" in C++. I knew it
could be done faster in VB than I was doing, I just didn't quite know where
to start.

thanks again,
Brian
Nov 21 '05 #7
Samuel,

I find your answer confusing (however read further)

You give as only one direct the exact right answer (I surely would have
given the stringbuilder answer as well, while I know this Join) and than
you can (mis) read from your message that the stringbuilder is better.

What it is in my opinion not the case. Your join answer is in my opinion the
best.

(As well meant to the OP of course)

Cor
Nov 21 '05 #8
Why do you think join is better? Any hard facts supporting either way?

Chris

"Cor Ligthert" <no************ @planet.nl> wrote in message
news:uB******** *****@TK2MSFTNG P09.phx.gbl...
Samuel,

I find your answer confusing (however read further)

You give as only one direct the exact right answer (I surely would have
given the stringbuilder answer as well, while I know this Join) and than
you can (mis) read from your message that the stringbuilder is better.

What it is in my opinion not the case. Your join answer is in my opinion
the best.

(As well meant to the OP of course)

Cor

Nov 21 '05 #9
Do take a look of GetEnumerator() that might help.

chanmm

"DumberThanSnot " <Du************ @nospam.com> wrote in message
news:uy******** ******@TK2MSFTN GP12.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("Str ing 1")
arList.Add("Str ing 2")
arList.Add("Str ing 3")

' I'd like to replace the following loop with something faster
sText = ""
for iCntr = 0 to arList.Count - 1
sText += arList.Item(iCn tr)
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

Nov 21 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

30
13757
by: franky.backeljauw | last post by:
Hello, I am wondering which of these two methods is the fastest: std::copy, which is included in the standard library, or a manually written pointer copy? Do any of you have any experience with this? I would think that the library function std::copy would perform optimally, as it is a library function, and therefore the writers of this function would know best how to optimize it ... but some tests seem to indicate that my pointer copy...
1
18016
by: Matt Garman | last post by:
What is the "best" way to copy a vector of strings to an array of character strings? By "best", I mean most elegantly/tersely written, but without any sacrifice in performance. I'm writing an application using C++ and the STL for handling my data. Unfortunately, I must interact with a (vanilla) C API. I use vectors of strings (for simplicity and less memory hassle), but the function calls for this API require arrays of character...
4
2789
by: Venkat | last post by:
Hi All, I need to copy strings from a single dimensional array to a double dimensional array. Here is my program. #include <stdio.h> #include <stdlib.h>
6
4107
by: Karl Ebener | last post by:
Hi! I am currently using a string to hold data (can be strings as well as binary!). Now it occured to me, that the <string> might be unable to handle Null-Bytes. Is that so? Following question: How can I copy the binary data of a string into an array, such as char mtext (or alike) ?
4
8828
by: Simon Schaap | last post by:
Hello, I have encountered a strange problem and I hope you can help me to understand it. What I want to do is to pass an array of chars to a function that will split it up (on every location where a * occurs in the string). This split function should allocate a 2D array of chars and put the split results in different rows. The listing below shows how I started to work on this. To keep the program simple and help focus the program the...
15
435
by: Kueishiong Tu | last post by:
How do I copy the content of a string in one encoding (in my case big5) to a char array (unmanaged) of the same encoding? I try the following String line = S"123æ°´æ³¥"; char buffer; for(int i=0; i<line->get_length(); i++) {
3
12799
by: marfi95 | last post by:
Hi all. I need to copy a byte array into a string, but starting at a specific location in the byte array. This is where I get hung up. For example if my byte array is (100) big, I might want to start at position 60 for example and copy from 60 to the next null byte in the array to my string. The starting position is variable, as is where the next null byte is in the byte array. The array I'm dealing with is much bigger than that, so...
17
2242
by: Chad | last post by:
I'm want static char *output; to hold the modified string "tel chad" However, when I debug it, static char *output holds the ascii value of the strng, and not the string itself. Here is what I have. I know gets(), strcat strcpy() shouldn't be used.
1
2058
by: illegal.prime | last post by:
I would like to have an array of objects (whose class I define) and then just invoke either: MyClass clonedArray = (MyClass) myArray.Clone(); OR Array.Copy(myArray, clonedArray, myArray.Length); and have an array of cloned objects (i.e. the new array of objects aren't the objects contained in my original array). But instead it seems necessary for me to have to iterate over my entire array and individually clone each element in the...
5
2472
by: tshad | last post by:
How do you easily make a copy of an arraylist? If you do: arrayList2 = arrayList1 You get a pointer so that if you clear arrayList2 (arrayList2.Clear) - arrayList1 is also cleared. I want to create a copy of the arrayList, which I can do looping through the
0
9672
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9519
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10438
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10164
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10001
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7540
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6780
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.