Xojo Developer Conference
25/27th April 2018 in Denver.
MBS Xojo Conference
6/7th September 2018 in Munich, Germany.

Quickest way to build a string? (Real Studio network user group Mailinglist archive)

Back to the thread list
Previous thread: Strange Project Errors
Next thread: RB Generated Application Info.plist causes log errors on Tiger and Leopard


Reading *CSV Files versus *.Txt Files   -   Claude Stone
  Quickest way to build a string?   -   Jeremy Cowgar
   Re: Quickest way to build a string?   -   Thomas Tempelmann
   Re: Quickest way to build a string?   -   Kem Tekinay
   Re: Quickest way to build a string?   -   Greg O'Lone
    Re: Quickest way to build a string?   -   Jeremy Cowgar
     Re: Quickest way to build a string?   -   Joe Strout
   Re: Quickest way to build a string?   -   Lars Jensen
   Re: Quickest way to build a string?   -   Norman Palardy
   Re: Quickest way to build a string?   -   Charles Yeomans
    Re: Quickest way to build a string?   -   Jeremy Cowgar
     Re: Quickest way to build a string?   -   Kem Tekinay
   Re: Quickest way to build a string?   -   Norman Palardy
   Re: Quickest way to build a string?   -   Charles Yeomans
    Re: Quickest way to build a string?   -   Jeremy Cowgar
     Re: Quickest way to build a string?   -   Joe Strout
     Re: Quickest way to build a string?   -   Jeremy Cowgar
   Re: Quickest way to build a string?   -   Christian Schmitz
   Re: Quickest way to build a string?   -   Charles Yeomans
   Re: Quickest way to build a string?   -   Theodore H. Smith
    Re: Quickest Way to Build a String?   -   Mnogojazyk aol.com

Quickest way to build a string?
Date: 30.01.09 00:17 (Thu, 29 Jan 2009 18:17:03 -0500)
From: Jeremy Cowgar
What is the quickest/best way to build a string? For instance:

myString = "John Doe"
myString = myString + " had "
myString = myString + " a "
myString = myString + " dog. "

is probably not the best way. Is there a class out there that deals with
a buffer and expands the buffer when necessary?

myBuf.Append "John Doe"
myBuf.Append " had "
... etc ...

Jeremy

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Re: Quickest way to build a string?
Date: 30.01.09 00:22 (Fri, 30 Jan 2009 00:22:03 +0100)
From: Thomas Tempelmann
RB has no StringBuffer or MutableString like Java or ObjC.

If someone would want to build something alike, and not use a Plugin
(there may be solutions as plugins already, I'm quite sure), you'd
build it on top of MemoryBlocks, which can be resized efficiently.

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Re: Quickest way to build a string?
Date: 30.01.09 00:25 (Thu, 29 Jan 2009 18:25:32 -0500)
From: Kem Tekinay
On 1/29/09 6:17 PM, "Jeremy Cowgar" <<email address removed>> wrote:

> What is the quickest/best way to build a string? For instance:

dim arr( -1 ) as string
arr.Append "John Doe"
arr.Append " had "
arr.Append " a "
arr.Append " dog. "

dim s as string = join( arr, "" ) // "John Doe had a dog. "

Or, if you know you always want a space between elements:

dim arr( -1 ) as string
arr.Append "John Doe"
arr.Append "had"
arr.Append "a"
arr.Append "dog."

dim s as string = join( arr, " " ) // "John Doe had a dog."

__________________________________________________________________________
Kem Tekinay (212) 201-1465
MacTechnologies Consulting Fax (914) 242-7294
http://www.mactechnologies.com Pager (917) 491-5546

To join the MacTechnologies Consulting mailing list, send an e-mail to:
<email address removed>






_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Re: Quickest way to build a string?
Date: 30.01.09 00:34 (Thu, 29 Jan 2009 18:34:10 -0500)
From: Greg O'Lone
Jeremy,

What are you trying to accomplish? There are a number of approaches
(including some that use memoryblocks for speed), but if you just want
to deal with a string, why not:

myString = "John Doe had a dog. "

or are you expecting the data to come into your program in pieces?

Greg

On Jan 29, 2009, at 6:17 pm, Jeremy Cowgar wrote:

> What is the quickest/best way to build a string? For instance:
>
> myString = "John Doe"
> myString = myString + " had "
> myString = myString + " a "
> myString = myString + " dog. "
>
> is probably not the best way. Is there a class out there that deals
> with a buffer and expands the buffer when necessary?
>
> myBuf.Append "John Doe"
> myBuf.Append " had "
> ... etc ...
>
> Jeremy
>
> _______________________________________________
> Unsubscribe or switch delivery mode:
> <http://www.realsoftware.com/support/listmanager/>
> Search the archives:
> <http://support.realsoftware.com/listarchives/lists.html>

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Re: Quickest way to build a string?
Date: 30.01.09 00:39 (Thu, 29 Jan 2009 18:39:51 -0500)
From: Jeremy Cowgar
Greg O'Lone wrote:
> Jeremy,
>
> What are you trying to accomplish? There are a number of approaches
> (including some that use memoryblocks for speed), but if you just want
> to deal with a string, why not:
>
> myString = "John Doe had a dog. "
>
> or are you expecting the data to come into your program in pieces?

Right now I am parsing wiki text converting it into RTF. I may have
something like:

----------------------
= Heading 1

This is a paragraph and **this is bold**, but //this is italic//.
----------------------

So, I am parsing it, when I get a chunk parsed (say "= Heading 1" should
be "{\fs24 Heading 1}\par "), then I am appending the appropriate "RTF
Prefix", the text and the appropriate "RTF Suffix" to a string, that in
the end will be a string suitable for saving as a RTF file.

Jeremy

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Re: Quickest way to build a string?
Date: 30.01.09 00:55 (Thu, 29 Jan 2009 16:55:37 -0700)
From: Joe Strout
Jeremy Cowgar wrote:

> So, I am parsing it, when I get a chunk parsed (say "= Heading 1" should
> be "{\fs24 Heading 1}\par "), then I am appending the appropriate "RTF
> Prefix", the text and the appropriate "RTF Suffix" to a string, that in
> the end will be a string suitable for saving as a RTF file.

Append each chunk to a string array, and then write them out (still as
an array) when you're done. If for some other reason you actually need
all the data as one string, then use Join as Karen suggested.

Best,
- Joe

Re: Quickest way to build a string?
Date: 30.01.09 01:03 (Thu, 29 Jan 2009 16:03:11 -0800)
From: Lars Jensen
I'd consider making a Text class to handle such things. I'd start with
a simple, slow implementation (probably based on String, and with a
nice unit tester), and then if performance actually proves to be an
issue, you can improve the Text class.

lj

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Re: Quickest way to build a string?
Date: 30.01.09 01:49 (Thu, 29 Jan 2009 17:49:15 -0700)
From: Norman Palardy

On 29-Jan-09, at 4:22 PM, Thomas Tempelmann wrote:

> RB has no StringBuffer or MutableString like Java or ObjC.
>
> If someone would want to build something alike, and not use a Plugin
> (there may be solutions as plugins already, I'm quite sure), you'd
> build it on top of MemoryBlocks, which can be resized efficiently.

Charles implemented such a thing a couple years ago :)

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Re: Quickest way to build a string?
Date: 30.01.09 03:45 (Thu, 29 Jan 2009 21:45:49 -0500)
From: Charles Yeomans

On Jan 29, 2009, at 7:49 PM, Norman Palardy wrote:

>
> On 29-Jan-09, at 4:22 PM, Thomas Tempelmann wrote:
>
>> RB has no StringBuffer or MutableString like Java or ObjC.
>>
>> If someone would want to build something alike, and not use a Plugin
>> (there may be solutions as plugins already, I'm quite sure), you'd
>> build it on top of MemoryBlocks, which can be resized efficiently.
>
> Charles implemented such a thing a couple years ago :)

But has since abandoned it in favor of string arrays and Join :)

Charles Yeomans

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Re: Quickest way to build a string?
Date: 30.01.09 14:16 (Fri, 30 Jan 2009 08:16:51 -0500)
From: Jeremy Cowgar
Charles Yeomans wrote:
>>
>> Charles implemented such a thing a couple years ago :)
>
> But has since abandoned it in favor of string arrays and Join :)

In your testing, that was the quickest way?

Jeremy

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Re: Quickest way to build a string?
Date: 30.01.09 14:36 (Fri, 30 Jan 2009 08:36:11 -0500)
From: Kem Tekinay
On 1/30/09 8:16 AM, "Jeremy Cowgar" <<email address removed>> wrote:

> In your testing, that was the quickest way?

I don't know about Charles, but in my testing, without resorting to a
plug-in, that was the fastest way.

If you know ahead of time the maximum number of elements your string will
have, it might be faster to allocate the array first:

dim arr( 10 ) as string
arr( 0 ) = "John Doe"
arr( 1 ) = " had "
etc..

My guess, without having tested it, is that this is faster than using Append
as long as you don't overdue it. Dimensioning the array to, say, 1 million
elements when your string won't have more than 10 is probably slower, but
this is easy enough to test.

__________________________________________________________________________
Kem Tekinay (212) 201-1465
MacTechnologies Consulting Fax (914) 242-7294
http://www.mactechnologies.com Pager (917) 491-5546

To join the MacTechnologies Consulting mailing list, send an e-mail to:
<email address removed>






_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Re: Quickest way to build a string?
Date: 30.01.09 05:13 (Thu, 29 Jan 2009 21:13:43 -0700)
From: Norman Palardy

On 29-Jan-09, at 7:45 PM, Charles Yeomans wrote:

> But has since abandoned it in favor of string arrays and Join :)

Didn't realize you hadn't just updated the stringbuffer to use that
method

I guess I should pay more attention :P

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Re: Quickest way to build a string?
Date: 30.01.09 14:28 (Fri, 30 Jan 2009 08:28:07 -0500)
From: Charles Yeomans

On Jan 30, 2009, at 8:16 AM, Jeremy Cowgar wrote:

> Charles Yeomans wrote:
>>>
>>> Charles implemented such a thing a couple years ago :)
>>
>> But has since abandoned it in favor of string arrays and Join :)
>
> In your testing, that was the quickest way?
>
> Jeremy

In my testing, arrays and Join. But how much concatentation are we
talking about?

Charles Yeomans

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Re: Quickest way to build a string?
Date: 30.01.09 14:46 (Fri, 30 Jan 2009 08:46:52 -0500)
From: Jeremy Cowgar
Charles Yeomans wrote:
>
> On Jan 30, 2009, at 8:16 AM, Jeremy Cowgar wrote:
>
>> Charles Yeomans wrote:
>>>>
>>>> Charles implemented such a thing a couple years ago :)
>>>
>>> But has since abandoned it in favor of string arrays and Join :)
>>
>> In your testing, that was the quickest way?
>>
>> Jeremy
>
> In my testing, arrays and Join. But how much concatentation are we
> talking about?

Some of the text files are ~100k in size. I have not run into a speed
problem, but if there is a right/wrong way of doing it, I'd rather do it
the right way to begin with. I know everyone says premature optimization
is evil, but no sense either in using the known fast method to start
with. I don't really profile my apps until I've got a good base in
place, but I don't use methods I know are slow either.

Jeremy

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Re: Quickest way to build a string?
Date: 30.01.09 16:58 (Fri, 30 Jan 2009 08:58:13 -0700)
From: Joe Strout
Jeremy Cowgar wrote:

> Some of the text files are ~100k in size. I have not run into a speed
> problem, but if there is a right/wrong way of doing it, I'd rather do it
> the right way to begin with. I know everyone says premature optimization
> is evil, but no sense either in using the known fast method to start
> with. I don't really profile my apps until I've got a good base in
> place, but I don't use methods I know are slow either.

If there's a method that's both faster AND clearer (or at least, just as
clear) as another, you should use it from the start. In this case, I
really think a string array fits the bill.

Best,
- Joe

Re: Quickest way to build a string?
Date: 30.01.09 17:07 (Fri, 30 Jan 2009 11:07:29 -0500)
From: Jeremy Cowgar
Jeremy Cowgar wrote:
> Some of the text files are ~100k in size. I have not run into a speed
> problem, but if there is a right/wrong way of doing it, I'd rather do
> it the right way to begin with. I know everyone says premature
> optimization is evil, but no sense either in using the known fast
> method to start with. I don't really profile my apps until I've got a
> good base in place, but I don't use methods I know are slow either.

Hm, that came out wrong :-) .... I meant to say, no sense in *not* using
the fast method to start with, if it's known.

Jeremy

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Re: Quickest way to build a string?
Date: 30.01.09 15:09 (Fri, 30 Jan 2009 15:09:50 +0100)
From: Christian Schmitz
Jeremy Cowgar <<email address removed>> wrote:

> is probably not the best way. Is there a class out there that deals with
> a buffer and expands the buffer when necessary?

StringHandleMBS does that.

But an array and join may be the best way without plugin.

Gruß
Christian

-

Re: Quickest way to build a string?
Date: 30.01.09 17:36 (Fri, 30 Jan 2009 11:36:56 -0500)
From: Charles Yeomans

On Jan 30, 2009, at 11:07 AM, Jeremy Cowgar wrote:

> Jeremy Cowgar wrote:
>> Some of the text files are ~100k in size. I have not run into a
>> speed problem, but if there is a right/wrong way of doing it, I'd
>> rather do it the right way to begin with. I know everyone says
>> premature optimization is evil, but no sense either in using the
>> known fast method to start with. I don't really profile my apps
>> until I've got a good base in place, but I don't use methods I know
>> are slow either.
>
> Hm, that came out wrong :-) .... I meant to say, no sense in *not*
> using the fast method to start with, if it's known.

And it is. This is a topic that has been beaten to death, revived,
and beaten again over the years on this list.

Charles Yeomans

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Re: Quickest way to build a string?
Date: 30.01.09 10:45 (Fri, 30 Jan 2009 09:45:02 +0000)
From: Theodore H. Smith

> From: Jeremy Cowgar <<email address removed>>
> What is the quickest/best way to build a string? For instance:
>
> myString = "John Doe"
> myString = myString + " had "
> myString = myString + " a "
> myString = myString + " dog. "
>
> is probably not the best way. Is there a class out there that deals
> with
> a buffer and expands the buffer when necessary?

The FastString class in my plugin.

fs = new FastString
fs.AppendData "John Doe"
fs.AppendData " had "
fs.AppendData " a "
fs.AppendData " dog. "

mystring = fs

FastString has so many tricks to make things faster... For example you
can set the size exactly if you want, or if not i assumes the size
doubles if it runs out of buffer space. Or it can even write to a file
when it runs out of internal buffer space, so there's no need to
resize the buffer at all.

it's also got so many utility functions to make things faster.
Like .AppendIntegerAsText...

Re: Quickest Way to Build a String?
Date: 30.01.09 05:54 (Fri, 30 Jan 2009 04:54:50 EST)
From: Mnogojazyk aol.com
Hello, all...

In a message dated 1/29/09 6:17 PM, Jeremy Cowgar writes:

> What is the quickest/best way to build a string? For instance:
>
> myString = "John Doe"
> myString = myString + " had "
> myString = myString + " a "
> myString = myString + " dog. "
>
> is probably not the best way. Is there a class out there that deals with
> a buffer and expands the buffer when necessary?
>
> myBuf.Append "John Doe"
> myBuf.Append " had "
> ... etc ...
>
Does Theodore H. Smith's FastString class satisfy you?
Here's the link: <http://www.elfdata.com/>

-- Charles Kelley.

**************
>From Wall Street to Main Street and
everywhere in between, stay up-to-date with the latest news.
(http://aol.com?ncidàlcntaolcom00000023)
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>