Free Support Forum - aspose.com

Spaces replaced with Question Marks

aspose.words 4.4.3, using the following code but when the .doc gets made some of the spaces are replaced with question marks, particularly a lot of spaces in a row. what causes this?

Dim buffer() As Byte
Dim encoder As New System.Text.ASCIIEncoding
Dim str As String = "AllTextHere"
ReDim buffer(str.Length - 1)
encoder.GetBytes(str, 0, str.Length, buffer, 0)

Dim ms As MemoryStream = New MemoryStream(buffer, False)

Dim license As Aspose.Words.License = New Aspose.Words.License
license.SetLicense(Request.ServerVariables("APPL_PHYSICAL_PATH") + "bin\Aspose.Words.lic")
Dim license2 As Aspose.pdf.License = New Aspose.pdf.License
license2.SetLicense(Request.ServerVariables("APPL_PHYSICAL_PATH") + "bin\Aspose.PDF.lic")

Dim WDoc As Aspose.Words.Document = New Aspose.Words.Document(ms)

Hello!<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for your inquiry.

In the code fragment you are converting a string with HTML document to byte array with its ASCII representation. Ensure your document doesn’t contain characters that cannot be represented in ASCII. In general it’s better to use UTF-8 or any other Unicode encoding.

Regards,

if i used UTF-8, the question marks turn to capital A's with carots over them. if i change to unicode encoding, I get an error on the

Dim WDoc As Aspose.Words.Document = New Aspose.Words.Document(ms)

line, the error is

Exception Details: Aspose.Words.UnsupportedFileFormatException: Unknown file format.

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. Please try using the following code:

Dim buffer() As Byte

Dim str As String = "AllTextHere"

buffer = System.Text.Encoding.UTF8.GetBytes(str)

Dim ms As MemoryStream = New MemoryStream(buffer)

Dim WDoc As Aspose.Words.Document = New Aspose.Words.Document(ms)

Hope this helps.

Best regards.