Carl,
| Is it possible to use special characters like \n or \t in a VB.NET
| string, just like in C#?
As the others have pointed out \n & \t are a compile time feature of C#, not
a runtime feature.
It sounds like you want a runtime feature that will convert the C# escape
sequences into valid chars. I don't know how complete it is, RegEx.Unescape
will unescape most if not all of the C# escape sequences.
http://msdn.microsoft.com/library/d...regularexpressionsregexclassunescapetopic.asp
Alternatively I would consider using a RegEx.Replace with a MatchEvaluator
function.
Something like:
Private Shared Function EscapeCharacters(ByVal match As Match) As String
Select Case match.Value
Case "\b"
Return ControlChars.Back
Case "\t"
Return ControlChars.Tab
Case "\r"
Return ControlChars.Cr
Case "\v"
Return ControlChars.VerticalTab
Case "\f"
Return ControlChars.FormFeed
Case "\n"
Return ControlChars.Lf
Case Else
Return match.Value.Substring(1)
End Select
End Function
Const pattern As String = "\\."
Static parser As New Regex(pattern, RegexOptions.Compiled)
Dim input As String
Dim output As String
input = parser.Replace(input, AddressOf EscapeCharacters)
The advantage of RegEx.Replace is you have control over how the escape
sequences are defined. For example you could use {Back}, {Tab}, {Cr}, ...
instead.
With effort it should be easy to add support for octal (\040), hex (\x20),
control (\cC), unicode (\u0020) sequences.
Hope this helps
Jay
| Hi,
|
| Is it possible to use special characters like \n or \t in a VB.NET
| string, just like in C#? My guess is NO, but maybe there's something I
| don't know.
|
| If it's not possible, does anybody know of a VB.NET function (somebody
| must have coded this already) that will interpret strings containings
| those special characters, and handle them the same as in C#?
|
| Thanks!