473,804 Members | 3,776 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
12 4931
Chris,

Only because that it shows what you do in one statement.

I am not interested in the performance because that is probably about
nanoseconds in this case.

I am extremly propaganding however forever the stringbuilder in this
newsgroup and when you would search for it than you would see, that I have
had very hard discussions about that.

:-)

Cor


Nov 21 '05 #11
Cor,

You're right, I wasn't very clear.

What I meant was that the code sample provided using String.Join was
the best solution to the stated question--how to join an ArrayList of
strings in a single line.

The comment about StringBuilder was a secondary comment to the code
from the OP where he had used a loop with standard old string
concatenation to perform the same operation. My intention here was to
state that StringBuilder was better than old style string
concatenation, but not that it was better than String.Join.

The quick answer is not always best if it's not explained--your point
is taken.

Thanks,

Sam
On Thu, 3 Feb 2005 17:11:08 +0100, "Cor Ligthert"
<no************ @planet.nl> wrote:
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 #12
"Chris, Master of All Things Insignificant" <chris@No_Spam_ Please.com>
schrieb:
Why do you think join is better? Any hard facts supporting either way?


I *assume* its implementation is "optimized" , because its not implemented in
the 'String' class directly:

<URL:http://www.123aspx.com/Rotor/RotorSrc.aspx?r ot=42059>

--
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 #13

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

Similar topics

30
13763
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
18019
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
2790
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
4108
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
8829
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
12800
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
2475
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
9706
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
9584
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
10337
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10323
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
10082
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...
0
9160
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
4301
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
2
3822
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2995
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.