How to remove \\x00 from a string

Got an odd attachment name. The original data is

which is quoted printable encoded ISO text, which is fine. At the end of the string, however, there is a \x00 character. Which makes code like

dim theAttachment as FolderItem = GetFolderItem(name) NameExtension = getExtensionFromFile(Name)

fail with an NOE. So I thought I’d simply get rid of the character. But how do I do this? A replace with “\x00” failed. Same for a more general regex:

dim theRegex as new RegEx theRegex.options.ReplaceAllMatches = true theRegex.searchpattern = "\\x00|\\x01|\\x02|\\x03|\\x04|\\x05|\\x06|\\x07|\\x08|\\x0E|\\x0F|\\x10|\\x11|\\x12|\\x13|\\x14|\\x15|\\x16|\\x17|\\x18|\\x19|\\x1A|\\x1B|\\x1C|\\x1D|\\x1E" theRegex.replacementPattern = "" theFilename = theRegex.replace(theFilename)

What am I missing here?

Whilst I cant comment on code you don’t show, the code you do show works by removing the trailing 00 (when viewing the variables as binary in the debugger) using this code:

[code]Dim theFilename As String

Dim s As String

s = “=?ISO-8859-1?Q?AntragPromotionser=F6ffnung=5FKBo=5Fv2.doc=00?=”

Dim a As String

a = DecodeQuotedPrintable(s)

Dim theRegex As New RegEx
theRegex.options.ReplaceAllMatches = True
theRegex.searchpattern = “\x00|\x01|\x02|\x03|\x04|\x05|\x06|\x07|\x08|\x0E|\x0F|\x10|\x11|\x12|\x13|\x14|\x15|\x16|\x17|\x18|\x19|\x1A|\x1B|\x1C|\x1D|\x1E”
theRegex.replacementPattern = “”

theFilename = theRegex.replace(a)

break[/code]

You’d have to post how you get name out of the string to try and find the issue as it seems that name isn’t correct if its throwing a NOE.

This won’t help to solve your issue, but I think the above could be replaced with a \\x0[xX][A-Fa-f0-9]+

The code is part of my upcoming Mime Parser. However, base64 always works for unprintable characters. The following does’t remove the \x00:

[code]Dim theFilename As String

Dim s As String = “QW50cmFnUHJvbW90aW9uc2Vyw7ZmZm51bmdfS0JvX3YyLmRvYwA=”
s = DecodeBase64(s)
s = DefineEncoding(s, Encodings.UTF8)
Dim theRegex As New RegEx
theRegex.options.ReplaceAllMatches = True
theRegex.searchpattern = “\x0[xX][A-Fa-f0-9]+”
theRegex.replacementPattern = “”

theFilename = theRegex.replace(s)[/code]

In both s and theFilename I can see the \x00 at the end of the string.

[code]Dim theFilename As String

Dim s As String = “QW50cmFnUHJvbW90aW9uc2Vyw7ZmZm51bmdfS0JvX3YyLmRvYwA=”
s = DecodeBase64(s)
s = DefineEncoding(s, Encodings.UTF8)
Dim theRegex As New RegEx
theRegex.options.ReplaceAllMatches = True
theRegex.searchpattern = “\x00|\x01|\x02|\x03|\x04|\x05|\x06|\x07|\x08|\x0E|\x0F|\x10|\x11|\x12|\x13|\x14|\x15|\x16|\x17|\x18|\x19|\x1A|\x1B|\x1C|\x1D|\x1E”
theRegex.replacementPattern = “”

theFilename = theRegex.replace(s)[/code]

Works fine here, Windows 10, 2018r4

[code]Dim theFilename As String

Dim s As String = “QW50cmFnUHJvbW90aW9uc2Vyw7ZmZm51bmdfS0JvX3YyLmRvYwA=”
s = DecodeBase64(s)
s = DefineEncoding(s, Encodings.UTF8)
Dim theRegex As New RegEx
theRegex.options.ReplaceAllMatches = True
theRegex.searchpattern = “\x0[xX][A-Fa-f0-9]+”
theRegex.replacementPattern = “”

theFilename = theRegex.replace(s)[/code]

Doesn’t work.

Thanks, Julian. Don’t know what I did wrong in the morning.

FYI, you can specify ranges within a character class, like this:

[\\x00-\\x08\\x0E-\\x1E]

But I think I would have done this:

[\\x00-\\x1F]

If it’s a filename, you wouldn’t want any of these characters, including tab or an EOL character, right?

Have you tried:
ReplaceAll(inputString,chr(0),"")