|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Strip chars from a stringThat code doesn't work, at least not in VS2005. What happens is that when you replace with VBNullChar, it basically chops off the string from that point onwards. So Sna?*|fu" would become Sna instead of Snafu. If you use two double quotes, then it works as you expect. Here is corrected code: strNewFileName = InputBox("Enter the new base file name: ") ' Check for invalid filename characters. For Each invalidChar As Char In System.IO.Path.GetInvalidFileNameChars strNewFileName = strNewFileName .Replace(invalidChar, "") Next Note that there is also a System.IO.Path.GetInvalidPathChars function. Not really sure what the difference is but I guess there must be some characters that are allowed in the filename but not the folder name, or vice-versa. Also, System.IO.Path.InvalidPathChars has been replaced by the two functions I mentioned above - you get an error if you try to use System.IO.Path.InvalidPathChars in VS2005. =================================================================== From: Tom Shelton Date: Thurs, Feb 10 2005 2:39 am Email: Tom Shelton <tshel***@YOUKNOWTHEDRILLcomcast.net> Groups: microsoft.public.dotnet.languages.vb On 2005-02-09, Nikolay Petrov <johntup2_nosp***@mail.bg> wrote: > I need a way to strip chars from a string. The chars are all chars that are What ever way you do it - I would make sure that you get the list of> not allowed in file path. > TIA illegal chars from the System.IO.Path class's InvalidPathChars property. One way, would be to build a regular expression (as Herfried suggested). Or you could do it something like: For Each invalidChar As Char In System.IO.Path.InvalidPathChars thePathString = thePathString.Replace (invalidChar, vbNullChar) Next HTH -- Tom Shelton [MVP] Function CleanInput(ByVal strIn As String) As String
Return Regex.Replace(strIn, "[^\w\.@-]", "") End Function -- Show quoteHide quoteGet a powerful web, database, application, and email hosting with KJM Solutions http://www.kjmsolutions.com "ImageAnalyst" <haywo***@hotmail.com> wrote in message news:1146684271.774048.256410@v46g2000cwv.googlegroups.com... > Tom, Nikolay: > That code doesn't work, at least not in VS2005. What happens is that > when you replace with VBNullChar, it basically chops off the string > from that point onwards. So Sna?*|fu" would become Sna instead of > Snafu. If you use two double quotes, then it works as you expect. > Here is corrected code: > strNewFileName = InputBox("Enter the new base file name: ") > ' Check for invalid filename characters. > For Each invalidChar As Char In > System.IO.Path.GetInvalidFileNameChars > strNewFileName = strNewFileName .Replace(invalidChar, > "") > Next > > Note that there is also a System.IO.Path.GetInvalidPathChars function. > Not really sure what the difference is but I guess there must be some > characters that are allowed in the filename but not the folder name, or > vice-versa. Also, System.IO.Path.InvalidPathChars has been replaced > by the two functions I mentioned above - you get an error if you try to > use System.IO.Path.InvalidPathChars in VS2005. > > > > =================================================================== > From: Tom Shelton > Date: Thurs, Feb 10 2005 2:39 am > Email: Tom Shelton <tshel***@YOUKNOWTHEDRILLcomcast.net> > Groups: microsoft.public.dotnet.languages.vb > > On 2005-02-09, Nikolay Petrov <johntup2_nosp***@mail.bg> wrote: > >> I need a way to strip chars from a string. The chars are all chars that >> are >> not allowed in file path. > >> TIA > > > What ever way you do it - I would make sure that you get the list of > illegal chars from the System.IO.Path class's InvalidPathChars > property. > > One way, would be to build a regular expression (as Herfried > suggested). > Or you could do it something like: > > > For Each invalidChar As Char In System.IO.Path.InvalidPathChars > thePathString = thePathString.Replace (invalidChar, vbNullChar) > > Next > > > HTH > -- > Tom Shelton [MVP] >
User permission problems. sqlconnection
Ho do I create a program that can get recognized as a printer driver and installed with the add prin incompatibility with dotnet 2.0 and Outlook Business Contact Manager 2003 On the fly formatting of textbox contents How can I embedd graphics in Outlook Email without using MAPI Register DLL for COM interop and use it in ASP help in search&replace for ArrayList Help with creating Installation package under VB2005 Express Ed. System.Configuration.ConfigurationSettings.AppSettings.Get("...") Question about the data adaptor Fill method. |
|||||||||||||||||||||||