• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

VBScript String Clean function - remove or replace illegal characters

D

dsoutter

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

This article provides a function written in VBScript which removes
illegal characters from a string. The illegal characters are specified
in an array at the beginning of the function. The function is passed
the string which may contain illegal characters, which then processes
the string to remove or replace any illegal characters. The code also
allows you to specify the character or word which will replace
specific illegal characters. The illegal characters provided in the
function are included for processing strings which will become the
filename of a document or list item in SharePoint, which has a number
of characters which are not accepted.

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

My Computer

P

Pegasus [MVP]

#2
"dsoutter" <dsoutter@newsgroup> said this in news item
news:f3309e77-8c29-42a3-8261-6d9d66d81ad6@newsgroup

> http://www.code-tips.com/2009/04/vbscript-string-clean-function-remove.html
>
> This article provides a function written in VBScript which removes
> illegal characters from a string. The illegal characters are specified
> in an array at the beginning of the function. The function is passed
> the string which may contain illegal characters, which then processes
> the string to remove or replace any illegal characters. The code also
> allows you to specify the character or word which will replace
> specific illegal characters. The illegal characters provided in the
> function are included for processing strings which will become the
> filename of a document or list item in SharePoint, which has a number
> of characters which are not accepted.
>
> http://www.code-tips.com/2009/04/vbscript-string-clean-function-remove.html
The code you posted just loops forever. I also wonder if the method you use
is suitable for this purpose since string manipulation is very expensive in
terms of processor time. I suspect that a regular expression might be the
way to go.
 

My Computer

A

Al Dunbar

#3
"Pegasus [MVP]" <news@newsgroup> wrote in message
news:#moKYtZgKHA.1536@newsgroup

>
>
> "dsoutter" <dsoutter@newsgroup> said this in news item
> news:f3309e77-8c29-42a3-8261-6d9d66d81ad6@newsgroup

>> http://www.code-tips.com/2009/04/vbscript-string-clean-function-remove.html
>>
>> This article provides a function written in VBScript which removes
>> illegal characters from a string. The illegal characters are specified
>> in an array at the beginning of the function. The function is passed
>> the string which may contain illegal characters, which then processes
>> the string to remove or replace any illegal characters. The code also
>> allows you to specify the character or word which will replace
>> specific illegal characters. The illegal characters provided in the
>> function are included for processing strings which will become the
>> filename of a document or list item in SharePoint, which has a number
>> of characters which are not accepted.
>>
>> http://www.code-tips.com/2009/04/vbscript-string-clean-function-remove.html
>
> The code you posted just loops forever. I also wonder if the method you
> use is suitable for this purpose since string manipulation is very
> expensive in terms of processor time. I suspect that a regular expression
> might be the way to go.
I got dizzy trying to verify the infinite loop thing. You may be right about
regular expressions, however, I would suggest the code (even if it works) is
overly complex. I would have done something more along these lines:

create a dictionary object with the key set to the restricted character
and the value set to what it is to be replaced with
for each key in dicob.keys
filename = replace( filename, key, dicob(key))
next

But, beyond that, I don't see the point of this function. If it processes an
invalid filename, the correct file might not be one with the name
calculated. It might be used to qualify a tentative filename the user
enters, however, it seems to remove valid filename/path characters such as
"." and "\".

/Al
 

My Computer

Users Who Are Viewing This Thread (Users: 1, Guests: 0)