Strip spaces from string 
Author Message
 Strip spaces from string

Is there a function to strip spaces from a string?

EXAMPLE: FROM Here is an example TO hereisanexample



Tue, 05 Aug 2003 02:57:13 GMT  
 Strip spaces from string
Hi LMS,

Wich version of Word are you using? If 2000 there's a built-in function
Replace that let you do this. If 97 you need to write your own, but can crib
at :
"Replace one character with another wherever it appears in a string"
http://www.mvps.org/word/FAQs/MacrosVBA/ReplaceCharInString.htm

Hope this helps,
regards,
Astrid

So that all can benefit from the discussion, please post all follow-ups to
the newsgroup.

Visit the MVP Word FAQ site at http://www.mvps.org/word/



| Is there a function to strip spaces from a string?
|
| EXAMPLE: FROM Here is an example TO hereisanexample
|
|



Tue, 05 Aug 2003 03:12:40 GMT  
 Strip spaces from string
Hi Larry,

AFAIK this works exactly the same in Access as in Word VBA.

Hope this helps,
regards,
Astrid

So that all can benefit from the discussion, please post all follow-ups to
the newsgroup.

Visit the MVP Word FAQ site at http://www.mvps.org/word/

Quote:
----- Original Message -----
From: "Lawrence Michael Siers" <

Sent: Thursday, February 15, 2001 8:26 PM
Subject: RE: Strip spaces from string

> I'm actually working in Access 97. I'm taking the value from a field
within
> a table (which may or may not contain spaces) and then using that value as
> the filename of a text file that the procedure will create to then write
> information into. Because of other things that will be happening later on,
> the filename can not have spaces. I know I can go back after the files are
> created and rename them however, there will be way too many files for this
> to be a good approach.

> larry

> -----Original Message-----

> Sent: Thursday, February 15, 2001 1:13 PM
> To: L M S
> Subject: Re: Strip spaces from string

> Hi LMS,

> Wich version of Word are you using? If 2000 there's a built-in function
> Replace that let you do this. If 97 you need to write your own, but can
> crib
> at :
> "Replace one character with another wherever it appears in a string"
> http://www.mvps.org/word/FAQs/MacrosVBA/ReplaceCharInString.htm

> Hope this helps,
> regards,
> Astrid

> So that all can benefit from the discussion, please post all follow-ups to
> the newsgroup.

> Visit the MVP Word FAQ site at http://www.mvps.org/word/



> | Is there a function to strip spaces from a string?
> |
> | EXAMPLE: FROM Here is an example TO hereisanexample



Tue, 05 Aug 2003 03:38:16 GMT  
 Strip spaces from string
 I know I'm a lttle late in coming to this one, so sorry if you've
already solved it.
Don't know about a built-in function, but this does the job pretty
nicely:

s$ = "String from which to remove stuff"
t$ = " " ' string to remove from S$
Do
i% = InStr(1, s$, t$)
If i% Then s$ = Left$(s$, i% - 1) & Mid$(s$, i% + Len(t$)) Else Exit Do
Loop

If you only want to remove single character occurrences, you can use 1
instead of Len(t$).
For your specific case of removing spaces, it can be shortened to:

s$ = "String from which to remove stuff"
Do
i% = InStr(1, s$, " ")
If i% Then s$ = Left$(s$, i% - 1) & Mid$(s$, i% + 1) Else Exit Do
Loop

Quote:

> Is there a function to strip spaces from a string?

> EXAMPLE: FROM Here is an example TO hereisanexample



Thu, 14 Aug 2003 03:49:51 GMT  
 Strip spaces from string
Hi Freya,

Hope you do indentation while programming
or usefull names ?? ;-))

Here's another one:

Function StripSpaces(MyWholeString As String) As String
Dim strTemp As String
MyWholeString = Trim(MyWholeString)

For X = 1 To Len(MyWholeString)
    If Mid$(MyWholeString, X, 1) <> " " Then
        strTemp = strTemp & Mid$(MyWholeString, X, 1)
    End If
Next
StripSpaces = strTemp
End Function

? stripspaces("Asp Bcc Cdo DSO EDP FTP G")
AspBccCdoDSOEDPFTPG

Krgrds,
Perry



Quote:
> I know I'm a lttle late in coming to this one, so sorry if you've
> already solved it.
> Don't know about a built-in function, but this does the job pretty
> nicely:

> s$ = "String from which to remove stuff"
> t$ = " " ' string to remove from S$
> Do
> i% = InStr(1, s$, t$)
> If i% Then s$ = Left$(s$, i% - 1) & Mid$(s$, i% + Len(t$)) Else Exit Do
> Loop

> If you only want to remove single character occurrences, you can use 1
> instead of Len(t$).
> For your specific case of removing spaces, it can be shortened to:

> s$ = "String from which to remove stuff"
> Do
> i% = InStr(1, s$, " ")
> If i% Then s$ = Left$(s$, i% - 1) & Mid$(s$, i% + 1) Else Exit Do
> Loop


> > Is there a function to strip spaces from a string?

> > EXAMPLE: FROM Here is an example TO hereisanexample



Thu, 14 Aug 2003 07:15:38 GMT  
 Strip spaces from string
Indentation and useful names as required, sure. This was just an example
to show Larry how to what he asked about as compactly as possible - I
didn't feel obliged to make it pretty as well. But yes, I'm a firm
believer in readable code and lots of comments, although I do use things
like I%, J%, K% as very short-range temporary variables - the names are
a hangover from fortran integer days, and my own naming conventions
include the  notion that a meaningful name should only be used for
variables that have a wider application. Something like the index in
such a tiny loop doesn't qualify, and I would re-use such a variable in
many different places where I wanted to do something extremely local.
Quote:

> Hi Freya,

> Hope you do indentation while programming
> or usefull names ?? ;-))

> Here's another one:

> Function StripSpaces(MyWholeString As String) As String
> Dim strTemp As String
> MyWholeString = Trim(MyWholeString)

> For X = 1 To Len(MyWholeString)
>     If Mid$(MyWholeString, X, 1) <> " " Then
>         strTemp = strTemp & Mid$(MyWholeString, X, 1)
>     End If
> Next
> StripSpaces = strTemp
> End Function

> ? stripspaces("Asp Bcc Cdo DSO EDP FTP G")
> AspBccCdoDSOEDPFTPG

> Krgrds,
> Perry



> > I know I'm a lttle late in coming to this one, so sorry if you've
> > already solved it.
> > Don't know about a built-in function, but this does the job pretty
> > nicely:

> > s$ = "String from which to remove stuff"
> > t$ = " " ' string to remove from S$
> > Do
> > i% = InStr(1, s$, t$)
> > If i% Then s$ = Left$(s$, i% - 1) & Mid$(s$, i% + Len(t$)) Else Exit Do
> > Loop

> > If you only want to remove single character occurrences, you can use 1
> > instead of Len(t$).
> > For your specific case of removing spaces, it can be shortened to:

> > s$ = "String from which to remove stuff"
> > Do
> > i% = InStr(1, s$, " ")
> > If i% Then s$ = Left$(s$, i% - 1) & Mid$(s$, i% + 1) Else Exit Do
> > Loop


> > > Is there a function to strip spaces from a string?

> > > EXAMPLE: FROM Here is an example TO hereisanexample



Thu, 14 Aug 2003 12:36:44 GMT  
 Strip spaces from string
Hi Freya,

Quote:
> include the  notion that a meaningful name should only be used for
> variables that have a wider application

Only when wider application ?
Whatever happened to maintainability ?
And what about maintainance by other persons?

Krgrds,
Perry



Quote:
> Indentation and useful names as required, sure. This was just an example
> to show Larry how to what he asked about as compactly as possible - I
> didn't feel obliged to make it pretty as well. But yes, I'm a firm
> believer in readable code and lots of comments, although I do use things
> like I%, J%, K% as very short-range temporary variables - the names are
> a hangover from Fortran integer days, and my own naming conventions
> include the  notion that a meaningful name should only be used for
> variables that have a wider application. Something like the index in
> such a tiny loop doesn't qualify, and I would re-use such a variable in
> many different places where I wanted to do something extremely local.


> > Hi Freya,

> > Hope you do indentation while programming
> > or usefull names ?? ;-))

> > Here's another one:

> > Function StripSpaces(MyWholeString As String) As String
> > Dim strTemp As String
> > MyWholeString = Trim(MyWholeString)

> > For X = 1 To Len(MyWholeString)
> >     If Mid$(MyWholeString, X, 1) <> " " Then
> >         strTemp = strTemp & Mid$(MyWholeString, X, 1)
> >     End If
> > Next
> > StripSpaces = strTemp
> > End Function

> > ? stripspaces("Asp Bcc Cdo DSO EDP FTP G")
> > AspBccCdoDSOEDPFTPG

> > Krgrds,
> > Perry



> > > I know I'm a lttle late in coming to this one, so sorry if you've
> > > already solved it.
> > > Don't know about a built-in function, but this does the job pretty
> > > nicely:

> > > s$ = "String from which to remove stuff"
> > > t$ = " " ' string to remove from S$
> > > Do
> > > i% = InStr(1, s$, t$)
> > > If i% Then s$ = Left$(s$, i% - 1) & Mid$(s$, i% + Len(t$)) Else Exit
Do
> > > Loop

> > > If you only want to remove single character occurrences, you can use 1
> > > instead of Len(t$).
> > > For your specific case of removing spaces, it can be shortened to:

> > > s$ = "String from which to remove stuff"
> > > Do
> > > i% = InStr(1, s$, " ")
> > > If i% Then s$ = Left$(s$, i% - 1) & Mid$(s$, i% + 1) Else Exit Do
> > > Loop


> > > > Is there a function to strip spaces from a string?

> > > > EXAMPLE: FROM Here is an example TO hereisanexample



Thu, 14 Aug 2003 17:20:00 GMT  
 Strip spaces from string


Quote:
> Indentation and useful names as required, sure. This was just an example
> to show Larry how to what he asked about as compactly as possible - I
> didn't feel obliged to make it pretty as well. But yes, I'm a firm
> believer in readable code and lots of comments, although I do use things
> like I%, J%, K% as very short-range temporary variables - the names are
> a hangover from Fortran integer days, and my own naming conventions
> include the  notion that a meaningful name should only be used for
> variables that have a wider application. Something like the index in
> such a tiny loop doesn't qualify, and I would re-use such a variable in
> many different places where I wanted to do something extremely local.

Hi Freyja

In my opinion, code that I publish should always be written in such a way
that I can justify every single line of it as being the best I can possibly
do. That includes indentation and meaningful variable names. By published
code, I mean everything I write that might ever be seen by somebody else,
either by being posted in a newsgroup, or shown to a colleague within a
project. It's a good habit to have.

As for re-using the names of loop variables, I have got myself out of that
habit. When you have a few extra loop variables, the four bytes of each Long
are so insignificant that the slightly inefficient use of memory is
outweighed by the risk of bugs caused by re-using variables when in fact I
haven't finished with them. That is just my own opinion, and is a trade-off
I find beneficial in my own coding, as a result of introducing unnecessary
bugs into my own code in the past!

For code posted to newsgroups, where the aim is to help people who are less
experienced, I think there is an especial responsibility to make the code
look well though good coding habits such as indentation. It makes it easier
for less experienced people to understand what the code is doing, and it
offers an extra lesson by example that making the code clear to read is a
good idea.

As it happens, your code can also be speeded up quite a bit, by not going
through a$ character by character. String concatenation is slow in VBA, so
it's best to have as little of it much as possible. Also, your code assumes
that you will only ever want to strip out single characters. It's as easy to
make the code more general purpose in order to allow for strings of any
length to be stripped.

The following is my version. I've written this as a function that can be
dropped straight into a larger program

Function StripChar(ByVal strSource as String, _
        ByVal strStrip As String) As String

    Dim iStripPos As Long

    Do
        iStripPos = InStr(strSource, strStrip)

        If iStripPos = 0 Then
            Exit Do           'no more strStrip in strSource
        End If

        strSource = Left$(strSource, iStripPos - 1) & _
                Mid$(strSource, iStripPos + Len(strStrip))
    Loop

    StripChar = strSource

End Function



Thu, 14 Aug 2003 21:05:55 GMT  
 Strip spaces from string
Yeah, I figured I'd get some reaction to that. Well, wider application
to me is not a precise definition, but roughly I use it in the sense of
beyond the immediate few lines of code. Like in the example I first
posted, when execution leaves the Do...Next loop, I% is done with, its
value can not be relied on and it is as available as when the program
started. Same thing when it's used as the index in a For...Next loop. If
it's a loop that does some serious work, then yes, of course I use
something that makes sense, but if for instance, I want to leave five
blank lines, I will code it as:

For I% = 1 To 5: Print: Next I%

and even leave it on one line. I feel that is more readable and makes
more sense because the action of leaving five blank lines is one task.
Something like:

For LineCount = 1 To 5
Print
Next LineCount

for me personally, is more work and more confusing, because such a name
seems to imply that I'm keeping track of something for subsequent use.
Having long 'meaningful' names in a situation where they really don't
mean much of anything, and inventing a different one for every situation
seems to me to decrease readability. But that's just my opinion, worth
exactly what you paid for it. Jonathan makes a good point though, about
setting an example for beginners.

However, I'm much more interested in Jonathan's comment that the code
can be speeded up quite a bit. I posted two versions of the routine in
the same message. The second one was a strippped version that only
picked out single spaces, the first one, with Len(T$) picked out any
arbitrary string. I don't see much difference between my first version
and your version. I don't go through the string character by character -
I use the Instr function, same as you, to find the first occurrence of
the offending string and concatenate the segments surrounding it into a
new shorter string, again same as you. This is repeated until the remove
string is not found, whereupon the loop exits. Is there some subtle
difference in the code that I'm missing? I did some experimenting with
timing loops just now, and found a few interesting things. You may
already know them, being more experienced with VBA than me, but here
they are anyway:

1. If...Then...
on one line executes SLOWER than
IF...Then
...
End If

2. Defining the position pointer (iStripPos) as an Integer is SLOWER
than defining it as Long

3. The order in which the functions are defined makes a noticeable
difference in the execution speed. Being defined first has a definite
advantage.

4. You can speed your code up a little by defining another variable to
hold the length of strStrip, instead of computing it every time.

And one more minor point about meaningful name: I would probably name
such a function something like StripString or RemoveString rather than
StripChar, since you have it set up to remove arbitrary strings rather
than single characters.

Quote:

> Indentation and useful names as required, sure. This was just an example
> to show Larry how to what he asked about as compactly as possible - I
> didn't feel obliged to make it pretty as well. But yes, I'm a firm
> believer in readable code and lots of comments, although I do use things
> like I%, J%, K% as very short-range temporary variables - the names are
> a hangover from Fortran integer days, and my own naming conventions
> include the  notion that a meaningful name should only be used for
> variables that have a wider application. Something like the index in
> such a tiny loop doesn't qualify, and I would re-use such a variable in
> many different places where I wanted to do something extremely local.


> > Hi Freya,

> > Hope you do indentation while programming
> > or usefull names ?? ;-))

> > Here's another one:

> > Function StripSpaces(MyWholeString As String) As String
> > Dim strTemp As String
> > MyWholeString = Trim(MyWholeString)

> > For X = 1 To Len(MyWholeString)
> >     If Mid$(MyWholeString, X, 1) <> " " Then
> >         strTemp = strTemp & Mid$(MyWholeString, X, 1)
> >     End If
> > Next
> > StripSpaces = strTemp
> > End Function

> > ? stripspaces("Asp Bcc Cdo DSO EDP FTP G")
> > AspBccCdoDSOEDPFTPG

> > Krgrds,
> > Perry



> > > I know I'm a lttle late in coming to this one, so sorry if you've
> > > already solved it.
> > > Don't know about a built-in function, but this does the job pretty
> > > nicely:

> > > s$ = "String from which to remove stuff"
> > > t$ = " " ' string to remove from S$
> > > Do
> > > i% = InStr(1, s$, t$)
> > > If i% Then s$ = Left$(s$, i% - 1) & Mid$(s$, i% + Len(t$)) Else Exit Do
> > > Loop

> > > If you only want to remove single character occurrences, you can use 1
> > > instead of Len(t$).
> > > For your specific case of removing spaces, it can be shortened to:

> > > s$ = "String from which to remove stuff"
> > > Do
> > > i% = InStr(1, s$, " ")
> > > If i% Then s$ = Left$(s$, i% - 1) & Mid$(s$, i% + 1) Else Exit Do
> > > Loop


> > > > Is there a function to strip spaces from a string?

> > > > EXAMPLE: FROM Here is an example TO hereisanexample



Fri, 15 Aug 2003 04:15:41 GMT  
 Strip spaces from string
Hi Freyja,

Quote:

> However, I'm much more interested in Jonathan's comment that the code
> can be speeded up quite a bit. I posted two versions of the routine in
> the same message. The second one was a strippped version that only
> picked out single spaces, the first one, with Len(T$) picked out any
> arbitrary string. I don't see much difference between my first version
> and your version.

I apologise. On looking at the thread more closely, I see that the version
that went through the string character by character was written by Perry,
not by you. So that comment should have been directed towards Perry.

Quote:
> I don't go through the string character by character -
> I use the Instr function, same as you, to find the first occurrence of
> the offending string and concatenate the segments surrounding it into a
> new shorter string, again same as you. This is repeated until the remove
> string is not found, whereupon the loop exits. Is there some subtle
> difference in the code that I'm missing? I did some experimenting with
> timing loops just now, and found a few interesting things. You may
> already know them, being more experienced with VBA than me, but here
> they are anyway:

> 1. If...Then...
> on one line executes SLOWER than
> IF...Then
> ...
> End If

I expected that there wouldn't be much difference either way, but its
interesting to note.

I also wonder about the relative speed of code where several statements are
on the same line separated by colons, compared to when it is on separate
lines. I must benchmark that sometime.

Quote:

> 2. Defining the position pointer (iStripPos) as an Integer is SLOWER
> than defining it as Long

This one I did know about. Windows and the processors it runs on have a word
length of 32 bits, so doing 32 bit arithmetic involves no conversions to get
the data in and out of the registers. I'd expect the same to be true of
other languages such as C++ & Fortran.

Quote:

> 3. The order in which the functions are defined makes a noticeable
> difference in the execution speed. Being defined first has a definite
> advantage.

I'm not sure what you mean by this. Could you give an example? Do you mean
the order in which the functions are included in a module?

Quote:

> 4. You can speed your code up a little by defining another variable to
> hold the length of strStrip, instead of computing it every time.

Yes, that makes sense.

Quote:

> And one more minor point about meaningful name: I would probably name
> such a function something like StripString or RemoveString rather than
> StripChar, since you have it set up to remove arbitrary strings rather
> than single characters.

Agree with that as well.

--
Regards
Jonathan West - Word MVP
MultiLinker - Automated generation of hyperlinks in Word
Conversion to PDF & HTML
http://www.multilinker.com
Word FAQs at http://www.multilinker.com/wordfaq
Please post any follow-up in the newsgroup. I do not reply to Word questions
by email



Fri, 15 Aug 2003 05:46:48 GMT  
 Strip spaces from string

Quote:

> > 3. The order in which the functions are defined makes a noticeable
> > difference in the execution speed. Being defined first has a definite
> > advantage.

> I'm not sure what you mean by this. Could you give an example? Do you mean
> the order in which the functions are included in a module?

Yes, exactly that. I set up a simple timing test, giving your code and
my code the same set of strings to chew on. Yours ran a bit faster at
first, so I started hacking mine to mimic yours more and more closely.
That's how I found that the IF THEN was slower than IF THEN ENDIF, and
that LONG was faster than INTEGER. But when I chopped it to the point
where it was EXACTLY the same as yours except for variable name, and
yours was still faster, I started wondering. Initially I had it set up
as:

Function StringChar() ; Jonathan's
.
End Sub

Function RemoveString() ' Mine
.
End Sub

Sub Freyja
' Call the routines from here
End Sub

and your routine was always faster. When I changed it to:

Function RemoveString() ' Mine
.
End Sub

Function StringChar() ; Jonathan's
.
End Sub

Sub Freyja
' Call the routines from here
End Sub

mine became faster by the same amount. Not a lot, but there was a
difference. Interestingly enough, it is also faster if you code it as a
function. I thought it might go faster as a Sub with arguments passed
ByRef, because there is less string shuffling, but no, a Sub is slower.
Can't rely on what seems logical, I guess.



Fri, 15 Aug 2003 07:28:51 GMT  
 Strip spaces from string
Hi Jonathan,

Quote:
> I apologise. On looking at the thread more closely, I see that the version
> that went through the string character by character was written by Perry,
> not by you. So that comment should have been directed towards Perry.

The reason for me reacting to Freya's code was the presentation of which
in respect to VBA non experienced readers.
The code I came up with was intended to show other ways of presenting code
to non experienced readers, and the set up was therefor more important than
the performance itself ... It's a matter of point of view ...

Anyhow, I've expressed the difference of performance in milliseconds
in function GetTickCount from the kernel32 API and testing the 3 functions

Result printed below, but on a string with 3070(!) characters (incl spaces)
and
262 words, the difference in the 3 functions is not even 10 milliseconds ...
We're blowing this whole thing out of proportion, IMO

Krgrds,
Perry

'*****************************
Sub Tester()
Dim BeginTime As Long
    ActiveDocument.Paragraphs(1).Range.Select

    Debug.Print Len(Selection.Range.Text), _
        " number of characters"

    Debug.Print ActiveDocument.BuiltInDocumentProperties _
        (wdPropertyWords), " number of words"

    Debug.Print "Testing milliseconds Jonathan's code"
    BeginTime = GetTickCount
    s$ = StripChar(Selection.Range.Text, " ")
    Debug.Print GetTickCount - BeginTime
    Debug.Print "----- end of test 1 ----------"

    Debug.Print "Testing millseconds Perry's code"
    BeginTime = GetTickCount
    s$ = StripSpaces(Selection.Range.Text)
    Debug.Print GetTickCount - BeginTime
    Debug.Print "----- end of test 2 ----------"

    Debug.Print "Testing millseconds Freya's code"
    BeginTime = GetTickCount
    s$ = Freya(Selection.Range.Text)
    Debug.Print GetTickCount - BeginTime
    Debug.Print "----- end of test 3 ----------"
End Sub

Result:
 3070          number of characters
 262           number of words
Testing milliseconds Jonathan's code
 10
----- end of test 1 ----------
Testing millseconds Perry's code
 15
----- end of test 2 ----------
Testing millseconds Freya's code
 18
----- end of test 3 ----------



Quote:
> Hi Freyja,

> > However, I'm much more interested in Jonathan's comment that the code
> > can be speeded up quite a bit. I posted two versions of the routine in
> > the same message. The second one was a strippped version that only
> > picked out single spaces, the first one, with Len(T$) picked out any
> > arbitrary string. I don't see much difference between my first version
> > and your version.

> I apologise. On looking at the thread more closely, I see that the version
> that went through the string character by character was written by Perry,
> not by you. So that comment should have been directed towards Perry.

> > I don't go through the string character by character -
> > I use the Instr function, same as you, to find the first occurrence of
> > the offending string and concatenate the segments surrounding it into a
> > new shorter string, again same as you. This is repeated until the remove
> > string is not found, whereupon the loop exits. Is there some subtle
> > difference in the code that I'm missing? I did some experimenting with
> > timing loops just now, and found a few interesting things. You may
> > already know them, being more experienced with VBA than me, but here
> > they are anyway:

> > 1. If...Then...
> > on one line executes SLOWER than
> > IF...Then
> > ...
> > End If

> I expected that there wouldn't be much difference either way, but its
> interesting to note.

> I also wonder about the relative speed of code where several statements
are
> on the same line separated by colons, compared to when it is on separate
> lines. I must benchmark that sometime.

> > 2. Defining the position pointer (iStripPos) as an Integer is SLOWER
> > than defining it as Long

> This one I did know about. Windows and the processors it runs on have a
word
> length of 32 bits, so doing 32 bit arithmetic involves no conversions to
get
> the data in and out of the registers. I'd expect the same to be true of
> other languages such as C++ & Fortran.

> > 3. The order in which the functions are defined makes a noticeable
> > difference in the execution speed. Being defined first has a definite
> > advantage.

> I'm not sure what you mean by this. Could you give an example? Do you mean
> the order in which the functions are included in a module?

> > 4. You can speed your code up a little by defining another variable to
> > hold the length of strStrip, instead of computing it every time.

> Yes, that makes sense.

> > And one more minor point about meaningful name: I would probably name
> > such a function something like StripString or RemoveString rather than
> > StripChar, since you have it set up to remove arbitrary strings rather
> > than single characters.

> Agree with that as well.

> --
> Regards
> Jonathan West - Word MVP
> MultiLinker - Automated generation of hyperlinks in Word
> Conversion to PDF & HTML
> http://www.multilinker.com
> Word FAQs at http://www.multilinker.com/wordfaq
> Please post any follow-up in the newsgroup. I do not reply to Word
questions
> by email



Sat, 16 Aug 2003 02:00:55 GMT  
 Strip spaces from string
Hi Perry.

Thanks for posting your results. I'm surprised that VBA code that
compares characters actually runs faster than the built-in INSTR
function. It's true that the INSTR function has to start from the
beginning of the string each time, whereas your code only makes one pass
through the string. I'm going to try modifying it to start its search
from it left off last time and see what impact that has on it. It should
help and I feel sort of stupid for not writing it that way in the first
place.

I don't agree that we're blowing it out of proportion - it didn't appear
to me that this had turned into an argument by any means. At least, I
haven't approached it in that spirit, and I didn't get the feeling that
anybody else had either. It's more in the line of research for its own
sake, not necessarily that the results are going to be especially
earth-shaking. Most serious professionals in every field are constantly
looking at how to do things cheaper, faster, easier... in general,
better somehow, even if they don't always agree on just what is better.
That's how progress is made, when people are not satisfied with the
status quo, and try to invent something slicker. When I come up with
something like this, I don't post it with the thought that my code is 3
clock ticks faster, so everybody whose code is slower is a jerk. No,
it's like finding a shorcut to get somewhere, or discovering a new
restaurant. It's a "Hey, look what I found." attitude. If it interests
you, fine. If it happens to be useful to you, so much the better and
help yourself to my results. If not, no harm done.

Please don't get the idea that we're some sort of misers, greedily
hoarding every processor cycle. Most of us are just born tinkerers who
can't leave well enough alone. If we didn't have this attitude, we'd
probably be selling insurance for a living.



Sun, 17 Aug 2003 09:35:25 GMT  
 Strip spaces from string
Hi Freya,

Don't mistake my perception, eventhough that's natural
(sender/receiver principle, eh?) :-))

Quote:
> I don't agree that we're blowing it out of proportion - it didn't appear
> to me that this had turned into an argument by any means.

??
Any argument is welcome, as long as it sticks with the initiating lead.
In my perception (here we go go again :-)) it was the presentation
towards VBA non experienced readers ...
Of course, the discussion lead to performance and the only input
I made afterwards, was indeed measure it's performance ...
Again, actually not within the scope I was aiming at
(remember my still my perception)

Quote:
> Thanks for posting your results. I'm surprised that VBA code that
> compares characters actually runs faster than the built-in INSTR
> function.

The function I came up with was one 'first to come up, first to get on
paper'
and was never well considered in terms of performance; wasn't my aim ...
(remember the perception)
But yes, indeed this startles me as well ... When I have time, I'll have a
closer
look at this and will test some String functions and their performance.
I'll do it in the cleanest possible way, ie no other application open ...
etc.
Result of which can be either sent to the group or to your personal email
address ...

Quote:
> Please don't get the idea that we're some sort of misers

??
I didn't read that one :-))

Btw, I was pleasantly surprised by the Paint Brush thingie
Good luck with it ..

Krgrds,
Perry



Quote:
> Hi Perry.

> Thanks for posting your results. I'm surprised that VBA code that
> compares characters actually runs faster than the built-in INSTR
> function. It's true that the INSTR function has to start from the
> beginning of the string each time, whereas your code only makes one pass
> through the string. I'm going to try modifying it to start its search
> from it left off last time and see what impact that has on it. It should
> help and I feel sort of stupid for not writing it that way in the first
> place.

> I don't agree that we're blowing it out of proportion - it didn't appear
> to me that this had turned into an argument by any means. At least, I
> haven't approached it in that spirit, and I didn't get the feeling that
> anybody else had either. It's more in the line of research for its own
> sake, not necessarily that the results are going to be especially
> earth-shaking. Most serious professionals in every field are constantly
> looking at how to do things cheaper, faster, easier... in general,
> better somehow, even if they don't always agree on just what is better.
> That's how progress is made, when people are not satisfied with the
> status quo, and try to invent something slicker. When I come up with
> something like this, I don't post it with the thought that my code is 3
> clock ticks faster, so everybody whose code is slower is a jerk. No,
> it's like finding a shorcut to get somewhere, or discovering a new
> restaurant. It's a "Hey, look what I found." attitude. If it interests
> you, fine. If it happens to be useful to you, so much the better and
> help yourself to my results. If not, no harm done.

> Please don't get the idea that we're some sort of misers, greedily
> hoarding every processor cycle. Most of us are just born tinkerers who
> can't leave well enough alone. If we didn't have this attitude, we'd
> probably be selling insurance for a living.



Mon, 18 Aug 2003 02:20:19 GMT  
 
 [ 14 post ] 

 Relevant Pages 

1. Strip Spaces from string

2. Q: Strip Space from String

3. Strip Space from String

4. Space Space Space Space Space Space Space

5. Space Space Space Space Space Space Space

6. Space Space Space Space Space Space Space

7. disabling the space key or removing a space from a string

8. Function to Squeeze multiple spaces in a string to one space

9. how to strip white spaces, line characters from xml file (written by dataset.writexml)

10. Access module for stripping double spaces

11. How do I Strip Spaces?

12. stripping/trimming spaces AND line breaks... end-up

 

 
Powered by phpBB® Forum Software