From: dsoutter on
VBScript String Replace

http://www.code-tips.com/2009/04/vbscript-string-clean-function-remove.html

Remove or replace specific characters from a string. The article below
provides a function in VBScript to remove or replace characters in a
string.

VBScript String Replace

http://www.code-tips.com/2009/04/vbscript-string-clean-function-remove.html

remove Illegal Characters from a string: VBScript String Replace

http://www.code-tips.com/2009/04/vbscript-string-clean-function-remove.html

VBScript replace characters in string.
From: dsoutter on
http://groups.google.com/group/web-programming-seo/browse_thread/thread/9fcc0e6307ccbce0

On Mar 2, 4:11 pm, dsoutter <webmasterhub....(a)gmail.com> wrote:
> VBScript String Replace
>
> http://www.code-tips.com/2009/04/vbscript-string-clean-function-remov...
>
> Remove or replace specific characters from a string. The article below
> provides a function in VBScript to remove or replace characters in a
> string.
>
> VBScript String Replace
>
> http://www.code-tips.com/2009/04/vbscript-string-clean-function-remov...
>
> remove Illegal Characters from a string: VBScript String Replace
>
> http://www.code-tips.com/2009/04/vbscript-string-clean-function-remov...
>
> VBScript replace characters in string.

From: Al Dunbar on


"dsoutter" <webmasterhub.net(a)gmail.com> wrote in message
news:a49b3803-8e79-46eb-a8c2-61454f499ee7(a)a16g2000pre.googlegroups.com...
> http://groups.google.com/group/web-programming-seo/browse_thread/thread/9fcc0e6307ccbce0
>
> On Mar 2, 4:11 pm, dsoutter <webmasterhub....(a)gmail.com> wrote:
>> VBScript String Replace
>>
>> http://www.code-tips.com/2009/04/vbscript-string-clean-function-remov...
>>
>> Remove or replace specific characters from a string. The article below
>> provides a function in VBScript to remove or replace characters in a
>> string.
>>
>> VBScript String Replace
>>
>> http://www.code-tips.com/2009/04/vbscript-string-clean-function-remov...
>>
>> remove Illegal Characters from a string: VBScript String Replace
>>
>> http://www.code-tips.com/2009/04/vbscript-string-clean-function-remov...
>>
>> VBScript replace characters in string.
>

Here is how I would code this function if I ever needed such a thing:

msgbox clean("C:\<test>&<done>")

function clean (strtoclean)
strtemp = strtoclean
badchars =
Array("?","/","\",":","*","""","<",">","","&","#","~","%","{","}","+","_",".")
for each badchar in badchars
select case badchar
case "&": goodchar = " and "
case ":": goodchar = "-"
case else: goodchar = " "
end select
strtemp = replace( strtemp, badchar, goodchar )
next
clean = strtemp
end function

IMHO, this has the same result but the logic is somewhat simpler. What
benefit would I get from switching from my version to yours?

/Al


From: dsoutter on
On Mar 3, 3:16 pm, "Al Dunbar" <aland...(a)hotmail.com> wrote:
> "dsoutter" <webmasterhub....(a)gmail.com> wrote in message
>
> news:a49b3803-8e79-46eb-a8c2-61454f499ee7(a)a16g2000pre.googlegroups.com...
>
>
>
>
>
> >http://groups.google.com/group/web-programming-seo/browse_thread/thre...
>
> > On Mar 2, 4:11 pm, dsoutter <webmasterhub....(a)gmail.com> wrote:
> >> VBScript String Replace
>
> >>http://www.code-tips.com/2009/04/vbscript-string-clean-function-remov....
>
> >> Remove or replace specific characters from a string. The article below
> >> provides a function in VBScript to remove or replace characters in a
> >> string.
>
> >> VBScript String Replace
>
> >>http://www.code-tips.com/2009/04/vbscript-string-clean-function-remov....
>
> >> remove Illegal Characters from a string: VBScript String Replace
>
> >>http://www.code-tips.com/2009/04/vbscript-string-clean-function-remov....
>
> >> VBScript replace characters in string.
>
> Here is how I would code this function if I ever needed such a thing:
>
>     msgbox clean("C:\<test>&<done>")
>
>     function clean (strtoclean)
>         strtemp = strtoclean
>         badchars =
> Array("?","/","\",":","*","""","<",">","","&","#","~","%","{","}","+","_","­.")
>         for each badchar in badchars
>             select case badchar
>                 case "&": goodchar = " and "
>                 case ":": goodchar = "-"
>                 case else: goodchar = " "
>             end select
>             strtemp = replace( strtemp, badchar, goodchar )
>         next
>         clean = strtemp
>     end function
>
> IMHO, this has the same result but the logic is somewhat simpler. What
> benefit would I get from switching from my version to yours?
>
> /Al- Hide quoted text -
>
> - Show quoted text -

Hi Al, the logic is simpler as you are using the replace() function to
perform the string replace, where the function provided takes the left
and right parts of a string, either side of an illegal character. In
many cases, your method would be more suitable mainly due to the
simpler logic, especially when all instances of each character are to
be processed in the same way.

As the method provided parses the string character by character, you
should have greater control over the output when more complex
operations need to be performed, such as removing or replacing a
character only if it within a specific context:

Eg. replace "&" with " and " if padded with spaces or other specific
character, or with a "+" if not
"something & something else" would become "something and something
else"
"somethin&something else" would become "somethin+something else".

Eg. replace ":" only if NOT part of a url:

"the website is http://code-tips.com " would remain "the website is
http://code-tips.com "
"See Here: http://code-tips.com " would become "See Here http://code-tips.com
"

This would be achieved by either checking the previous 3-5 characters
when a ":" is found to see if it is in the context of a url or not
(http, https, ftp), or by checking the characters following the
current ":" is "//" which would indicate that the semicolon is part of
a url.

This functionality has not been included in the function provided, but
would be easy to implement, as the string is incrementally parsed and
manipulated using a numeric string position value relative to the
current position/character in the string.

There may also be differences in performance between the two methods,
as the function provided includes the code required to remove or
replace each of the specified characters without calling the replace()
function. I suspect that the replace function uses a similar approach
to replace the specified characters so any difference in performance
would be minimal, unless parsing a large string value. I haven't yet
tested this for performance differences.

Thanks
From: WebmasterHub.net on
On Mar 3, 3:16 pm, "Al Dunbar" <aland...(a)hotmail.com> wrote:
> "dsoutter" <webmasterhub....(a)gmail.com> wrote in message
>
> news:a49b3803-8e79-46eb-a8c2-61454f499ee7(a)a16g2000pre.googlegroups.com...
>
>
>
>
>
> >http://groups.google.com/group/web-programming-seo/browse_thread/thre...
>
> > On Mar 2, 4:11 pm, dsoutter <webmasterhub....(a)gmail.com> wrote:
> >> VBScript String Replace
>
> >>http://www.code-tips.com/2009/04/vbscript-string-clean-function-remov....
>
> >> Remove or replace specific characters from a string. The article below
> >> provides a function in VBScript to remove or replace characters in a
> >> string.
>
> >> VBScript String Replace
>
> >>http://www.code-tips.com/2009/04/vbscript-string-clean-function-remov....
>
> >> remove Illegal Characters from a string: VBScript String Replace
>
> >>http://www.code-tips.com/2009/04/vbscript-string-clean-function-remov....
>
> >> VBScript replace characters in string.
>
> Here is how I would code this function if I ever needed such a thing:
>
>     msgbox clean("C:\<test>&<done>")
>
>     function clean (strtoclean)
>         strtemp = strtoclean
>         badchars =
> Array("?","/","\",":","*","""","<",">","","&","#","~","%","{","}","+","_","­.")
>         for each badchar in badchars
>             select case badchar
>                 case "&": goodchar = " and "
>                 case ":": goodchar = "-"
>                 case else: goodchar = " "
>             end select
>             strtemp = replace( strtemp, badchar, goodchar )
>         next
>         clean = strtemp
>     end function
>
> IMHO, this has the same result but the logic is somewhat simpler. What
> benefit would I get from switching from my version to yours?
>
> /Al- Hide quoted text -
>
> - Show quoted text -

Hi Al, the logic is simpler as you are using the replace() function
to
perform the string replace, where the function provided takes the
left
and right parts of a string, either side of an illegal character. In
many cases, your method would be more suitable mainly due to the
simpler logic, especially when all instances of each character are to
be processed in the same way.

As the method provided parses the string character by character, you
should have greater control over the output when more complex
operations need to be performed, such as removing or replacing a
character only if it within a specific context:


Eg. replace "&" with " and " if padded with spaces or other specific
character, or with a "+" if not
"something & something else" would become "something and something
else"
"somethin&something else" would become "somethin+something else".


Eg. replace ":" only if NOT part of a url:


"the website is http://code-tips.com " would remain "the website is
http://code-tips.com "
"See Here: http://code-tips.com " would become "See Here http://code-tips.com
"


This would be achieved by either checking the previous 3-5 characters
when a ":" is found to see if it is in the context of a url or not
(http, https, ftp), or by checking the characters following the
current ":" is "//" which would indicate that the semicolon is part
of
a url.


This functionality has not been included in the function provided,
but
would be easy to implement, as the string is incrementally parsed and
manipulated using a numeric string position value relative to the
current position/character in the string.

There may also be differences in performance between the two methods,
as the function provided includes the code required to remove or
replace each of the specified characters without calling the
replace()
function. I suspect that the replace function uses a similar
approach
to replace the specified characters so any difference in performance
would be minimal, unless parsing a large string value. I haven't yet
tested this for performance differences.