|
-
May 27th, 2011, 08:43 AM
#1
Thread Starter
Fanatic Member
remove special characters from string
Is there a build in function that removes the following without doing a replace for each character?
"NUL", "SOH", "STX", "ETX", "EOT", "ENQ", "ACK", "BEL",
"BS", "HT", "LF", "VT", "FF", "CR", "SO", "SI",
"DLE", "DC1", "DC2", "DC3", "DC4", "NAK", "SYN", "ETB",
"CAN", "EM", "SUB", "ESC", "FS", "GS", "RS", "US"
-
May 27th, 2011, 09:01 AM
#2
Re: remove special characters from string
You've got no choice but to do each one, but there are various ways to do it. This would be the most succinct option:
vb.net Code:
Dim builder As New StringBuilder("NULaSTXbSOHcSTX") Dim substrings = {"NUL", "SOH", "STX"} Array.ForEach(substrings, Sub(s) builder.Replace(s, String.Empty)) MessageBox.Show(builder.ToString())
Using a StringBuilder makes it much more efficient than a String for many replacements.
-
May 27th, 2011, 09:03 AM
#3
New Member
Re: remove special characters from string
Use regular expressions.
Code:
Imports System.Text.RegularExpressions
TargetString = Regex.Replace(TargetString, "NUL|SOH|STX|ETX", "")
Just enter all the substrings as I showed with |'s separating them. Each of them will be replaced with nothing.
This will help you build additional regular expressions: http://www.regular-expressions.info/reference.html
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|