VBScript String Clean function - remove or replace illegal characters

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
0
dsoutter
12/20/2009 3:50:07 PM
scripting.vbscript 564 articles. 0 followers. Follow

2 Replies
1298 Views

Similar Articles

[PageSpeed] 34


"dsoutter" <dsoutter@iinet.net.au> said this in news item 
news:f3309e77-8c29-42a3-8261-6d9d66d81ad6@y10g2000prg.googlegroups.com...
> 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. 

0
Pegasus
12/20/2009 5:39:11 PM

"Pegasus [MVP]" <news@microsoft.com> wrote in message 
news:#moKYtZgKHA.1536@TK2MSFTNGP06.phx.gbl...
>
>
> "dsoutter" <dsoutter@iinet.net.au> said this in news item 
> news:f3309e77-8c29-42a3-8261-6d9d66d81ad6@y10g2000prg.googlegroups.com...
>> 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
 

0
Al
12/21/2009 5:42:14 AM
Reply:

Similar Artilces:

VBScript for SMTP admin
Hi all, I'm trying to find whether there's some way to admin SMTP virtual server by VBScript, not from GUI. I want to deploy multiple SMTP virtual servers on multiple boxes, so it's quite boring to click lots of time to do the same thing. Do you have any info, hint or simple samples to share? Many thanks. -Gavin Best start here http://www.microsoft.com/technet/scriptcenter/hubs/exchange.mspx . Also try posting the question to microsoft.public.scripting.vbscript group as well. "Gavin Lu" <gavin.lu@gmail.com> wrote in message news:1137398521.817458.1035...

Instr parsing with a comma delimited string
Hi all - I'm using the InStr function to parse a comma delimited text field for use in a parameter query. It works like a charm, except that the data in the field is very small and it's splitting by character. For example, here's the function I'm using in the query SQL (I snipped the rest of the SQL for space): InStr(1,[Forms]![frmAppliesTo].[txtSelections] & ",",[BOOK_ID]) Works great if what's in the text box is: 1 3 1,3 If, however, the text box is "13", it returns records for 1, 3, and 13. Any hints on how I could fix ...

Form Function Help
I am a technician for a Nextel Service Center, and I have developed a work order system using Excel 2002. It is replacing paper work orders to increase efficiency. It's a simple form, and the data input consists mostly of names, ID numbers, and descriptions. There's one field that contains a 5-digit work order number. What I want to do is, create a button that saves the worksheet with that work order number as the file name, clear all unlocked cells, and repopulate the work order number field one number higher. This would complete my system PERFECTLY!! Also, when I lock and pro...

Complex IIF function
I have a table that look like this: ID Opcode Date 123 Align 01/jan/06 Oil Break 569 Align 05/jan/06 Break Transmission Inspection 425 Oil 04/Jan/06 etc... I want to modifiy it with automatic macros to this: ID Opcode Date 123 Align 01/jan/06 123 Oil 01/jan/06 123 Break 01/jan/06 569 Align 05/jan/06 569 Break 05/jan/06 569 Transmission 05/jan/06 569 Inspection 05/jan/06 425 Oil 04/Jan/06 This would be easy in excel....

instr function
Outlook 2003 SP3 Hi, I'm trying to find * and ? in the string. Do I have to do two separate if statements, or can I use some kind of OR statement? This isn't working: If Instr(1, Item.UserProperties("JobName"), "*" or "?", vbTextCompare) > 0 Then MsgBox "Sorry, you cannot use the * or ? character" Exit Sub end if Thanks, Joel Joel Allen wrote: > Outlook 2003 SP3 > > Hi, > > I'm trying to find * and ? in the string. Do I have to do two separate if > statements, or can I us...

counting a string of negative or positive numbers
These are daily performance figures. How would I calculate the mos consecutive losing days and related to that, the largest drawdow (cummulative performance of that streak of losing days). What about th 2nd and 3rd longest streaks and drawdowns? My real set of numbers i >1000, so eyeballing it on a chart doesn't work. I'm thinking I wil need to use the sumif command, but haven't gotten any farther tha that. Thanks for any help you can provide. Megan 0.32% 0.73% 0.61% 0.90% -0.23% 0.41% 0.00% 0.24% -0.07% 0.09% -0.32% 0.46% 0.06% -0.81% 0.53% 0.40 -- mcarringto --------------...

Adding Right-Click Functionality
Is there a way I can add more options to the right click menus in CRM when I right click on an Object? If the whole thing uses ASP, shouldn't it be possible? HELP! Thanks! The context menus are generated in the code-behind pages, so it isn't that esy to modify them. You could do this thoguh with some javascript that modifes the resulting div on the fly when the age displays. This would not be a supported change though. Matt Parks MVP - Microsoft CRM ---------------------------------------- ---------------------------------------- On 24 May 2005 08:19:47 -0700, "IT Guy"...

Using "offset" functionality in graphs. HOW?
I have created worksheets which utilize "offset" functionality, so that on a weekly basis I only have to change a single value and multiple tables I have set up automatically change to roll with changes in dates. Now I have set up graphs to reflect the data, but find myself updating ranges inside the graphs weekly. I would like to use the same type of functionality so that the single field update I do ALSO changes the graph ranges. I tried to use the "offset" functionality in the source date - value section of the graph, but received an error message that the func...

illegal operation
When I run the specific program in windows 95 I get this message: This program has performed an illegal operation and will be shut down. If the problem persists, contact the program vendor. When I click Details, I receive the following error message: Program caused an invalid page fault in module program.exe at memory address. I believe you are most likely asking this in the wrong group. What program are you actually running that is failing? The other 2 problems you have here are: 1) You're running Windows 95 2) The maker of the application is normally who should be contacte...

are VBscript on Windows server 2003 and VBscript on WS2008 compatible?
Hi everybody, Sorry if my question has already been asked, but I haven't found anything which is clear for me on this point. I spent a lot of time learning VBscript on Windows server 2003 (my sources are script56.chm and script_center.chm files), especially VBscript for using Active Directory (creating user accounts etc). Now, I have several scripts and I'm rather satisfied. I would like to know if my scripts will always work on Windows server 2008 or if, after migration to Windows 2008, I would have to rewrite my scripts? Thanks in advance. -- Fran´┐Żois La...

Power, Max, Min Functions
Hi All, I am trying to convert some VBA code to VB code and have become stuck on the Power, Max and Min function built into excel. Does anybody know of any code that will offer the same ability in VB without reference to the excel dll's Excel code Application.power Application.Max Application.Min This is what I need to convert to VB. Thanks for your help James For POWER use ^ (exponential) Use IF to test for MAX and MIN, for example, Sub aa() Dim a, b a = 5 b = 6 If a > b Then Debug.Print a Else Debug.Print b End If End Sub OR ... Sub aaa() Dim a, b a = 5 b = 6 ...

How do I get the subset filter string from a pivotchart?
I have a form with a bunch of checkboxes representing fields in a table. Next to this form is a subform restricted to a pivotchart view. When a user clicks up to 5 of these categories, the categories are inserted into the filter dropzone in the pivotchart using an "apply filter" button. In the filter dropzone area, one can select or deselect members of the value list associated with each category/field. These selections will affect the 3 Min/Ave/Max areas locked in the series dropzone. What I need to get via VBA code, is the string expression (or however it's stored) ...

Add the same character(s) to multiple cells in a column (or row) .
I want to add the suffix "scc" into the contiguous cells of several columns on an existing Excel spreadsheet. There is existing data (alpha/numeric) in each of the cells already, so the scc suffix would be added to the right of the existing entries. I'm trying to avoid having to enter each suffix into each cell individually. I have Excel 2002 and Windows XP Professional. Thank you. Use a help formula =Sheet1!A1&"scc" copy down/across, then copy and paste special as values in place , finally replace the old values with the new Regards, Peo Sjoblom &qu...

MATCH function #4
How can I get the functionality of the MATCH function to match a text to the LAST match in a column. The MATCH function returns the location of the FIRST match. This example shows what I am trying to do: A B C 1 Name1 NumOfDays1 StartDate 2 Name2 NumOfDays2 3 Name3 NumOfDays3 4 Name5 NumOfDays4 5 Name1 NumOfDays5 6 Name5 NumOfDays6 7 Name1 NumOfDays7 8 Name2 NumOfDays8 9 Name5 NumOfDays9 NameN (in cloumn A) is a text and can have any value. NumOfDaysN (in column B) is an integer and have any value. StartDate(in cell C1) is a date. I need a...

VBScript
There's probably already an answer to this, somewhere, but it would take me forever to find it! I use CloudEight stationery frequently. Evidently I have installed an update to Outlook that keeps their beautiful stationery from scrolling. It was an update that disabled VBScript inside of Outlook (it still works fine in Outlook Express). CloudEight FAQ says to find out from MicroSoft how to RE- ENABLE VBScript for Outlook if I want to use it. I've been looking for over an hour, now, and have better things to do than to sit here all night looking for the answer. I'm hoping S...

Does VB allow function pointers?
I have a table that lists a large number of math problems, it contains the problem number, problem name, problem description, and name of the sub to be executed to solve the problem. I also have a form with a combo box that shows the descriptions of those problems. When I click on a particlular entry, I would like to execute the sub whose name is listed in the table. One way to do this is to have a long list of If name = "xxxnn" then xxxnn ElseIf name = "xxxny" then xxxny .. . . Endif statements. Is it possible in VB to call a sub using a variable t...

Request for help with VBScript...
Hi Forum, I have tried to write a VBScript (to be called using "cscript z:\folder\script.vbs") as a tool/utility to time email delivery. Basically it sends two emails, one to an email gateways providers echo service, and another to itself. The scripts purpose is to record delivery delay timings, as part of an excercise to determine and record quality of performance and service. Its pretty simple at the moment, and I would like to make it more detailed, and I would like to get it to run as a scheduled task either on a workstation or on a server. I have several problems wit...

Does Excel support mixed formatting of a string in a formula cell, yet?
Excel is one of the most spectacular apps ever created. But one feature I really need is mixed formatting of a string whose cell is a formula. By mixed formatting I mean, you know, making selected (as opposed to all) character(s) of the string bold, italic, a different color, sub- or superscripted, etc. In Excel 2002 you cannot do that in a formula cell (right?). In edit mode, the user would, say, press F9 to display the calc'ed string, selectively format it as usual, then cancel edit. Excel would save the formatting as a separate mask. What could be easier? The user would ...

I find a BIG bug of VS 2005 about string class!
I find a BIG bug of VS 2005 about string class! #include <iostream> #include <string> using namespace std; string GetStr() { return string("Hello"); } int main(int argc, char *argv[]) { const char* p = GetStr().c_str(); cout << p << endl; cin.get(); } ============================ Run the code above, Dev C++ will normally output the string "Hello", however, VS 2005 should output an empty string! In my opinion, string class is vital to almost every C++ program, and VS 2005 as a C++ compiler is widely used by programmers, if string class is...

Is There A Way to Test if Global Catalog Functioning Correctly
Still dealing with some cleanup issues from a DC loss last week. The DC was a Global Catalog server. However, I *believe* we had another one in place. At least, there was a checked GC box under the NTDS properties. However, I was wondering if there is some sort of test to make sure a GC is available and functioning before I proceed with the metadata cleanup of the dead domain controller? Not that it matters much at this point, I suppose. Still, it would be nice to go into this feeling comfortable about having a GC available. Thanks Hello Mark, See the last part ...

is there a way to convert a string (containing a number) into a 64bit integer variable?
hi, My string (a CString) contains a minimum free disk space as follow "1099511627776" and the method to get the free disk space gives 64 bits int. So I want to convert my string into a 64 bits int so I can compare the 2 values. I used to use atoi, but I don't know if it supports 64 bits int (I guess not). What would be the best way to do what I want? I found _strtoi64, but how do I use this thing? what is the 2nd parameter supposed to do? thanks ThunderMusic ThunderMusic wrote: >hi, > My string (a CString) contains a minimum free disk space as follow >&...

Function Parameter Type
Hi I'm having problem calling a method of a COM. The signature of the exposed method is like this. HRESULT GetMailLists(VARIANT* bstrLists) If I call this method from a C# code, the signature changes to void GetMailLists(out object bstrLists) In C#, I called it as object obList; users.GetMailingLists(out obList); and obList type changed to "System.Array" and was filled with an array of desired string values. Now the problem is that I have to use this method from my VC++ code and have to use late binding for using the COM. Can someone tell me how would I call this method ...

Cstring, string ,and char[]
I have a problems on the file io. when I use the dilog box to pick a txt file. code is like below. CFileDialog dlg(.......); if(dlg.DoModal() == IDOK) { Cstring a; a= dlg.GetPathName(); } the "a" will assigned a filename of the txt file. a is a Cstring type variable. but in standard c++ ,I use the string p; p=????;//p is the file full path. inFile.open(p); if (!inFile) { cout << "Unable to open file"; return; } where p is a standard string class. My question is How can I traslate among Cstring ,string and char[]. Is there any common methods? Thank yo...

due date function
I try to make function for due payment. When I made copy file and then drag down the formula and it's succed. But for the cell that I not fill yet has due date also. How to make that cell became 0 (zero) if not fill the cell yet. example : A1 A2 19/8/05 =A1+30 - 30/01/00 - 30/01/00 Thanks Lando =IF(C5=""; "" ;C5+30) Explanation detail if ([logical test] c5 equals ""; then [result if true] ""; else [result if false] c5+30) Explanation brief if c5 eq...

Why can I do this in VBScript...?
Hi, I'm currently making heavy use of an application that provides an ActiveX scripting/automation interface via VBScript. In those scripts a special object is made available which represent the application's various properties and methods. Works great. However it's not Powershell, so it's not perfect. My question is that if I can run VBScript against this object, why can't I simply instatiate this object in Powershell and use that. Thing is, search as I have amongst all the dark corners of new-object -com Sorry, you really haven't provide enough...