473,473 Members | 1,491 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Strip chars from a string

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]

May 3 '06 #1
2 5701
Function CleanInput(ByVal strIn As String) As String
Return Regex.Replace(strIn, "[^\w\.@-]", "")
End Function

--
Get a powerful web, database, application, and email hosting with KJM
Solutions
http://www.kjmsolutions.com

"ImageAnalyst" <ha******@hotmail.com> wrote in message
news:11**********************@v46g2000cwv.googlegr oups.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]

May 3 '06 #2
Imageanalyst.

Please keep your replies to the original question, I will not be the only
one who does not understand what you mean.

Cor

"ImageAnalyst" <ha******@hotmail.com> schreef in bericht
news:11**********************@v46g2000cwv.googlegr oups.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]

May 4 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Nikolay Petrov | last post by:
I need a way to strip chars from a string. The chars are all chars that are not allowed in file path. TIA
8
by: Scott | last post by:
Below is a script I use to strip everything from a url except the actual page. So for example, "http://www.cnn.com/mypage.asp?article=5&id=20" becomes "mypage.asp". I'm looking for a script that...
6
by: eight02645999 | last post by:
hi can someone explain strip() for these : 'example' when i did this: 'abcd,words.words'
3
by: BonBoni | last post by:
Hi everybody I need to implement a function that receives the following parameters : char *PrefixMin , char *PrefixMax , char *InputNum All the input strings max length is 25 chars. I can...
3
by: Colin J. Williams | last post by:
The Library Reference has strip( ) Return a copy of the string with the leading and trailing characters removed. The chars argument is a string specifying the set of characters to be removed....
4
by: Ethan Furman | last post by:
Greetings. The strip() method of strings works from both ends towards the middle. Is there a simple, built-in way to remove several characters from a string no matter their location? (besides...
0
by: Maric Michaud | last post by:
Le Monday 16 June 2008 18:58:06 Ethan Furman, vous avez écrit : As Larry Bates said the python way is to use str.join, but I'd do it with a genexp for memory saving, and a set to get O(1) test...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.