Solved

Invalid Characters-How to remove them?

Posted on 2004-10-15
3
158 Views
Last Modified: 2010-05-02
im converting an XML File to an Access Database.  the problem i keep having is the XML file is full of invalida characters like;
 and so on.  How can i clean up the data being saved to the xml file, i.e remove the invalid chars.  so far my sub looks like this but it just keeps getting longer;


Private Sub Clean_XML_Export2(myExportstruct As datastruct)
Dim s As String, tmp() As String, i As Integer
s = "&|" & Chr(34) & "|" & Chr$(0) & "|<|>|=|+|-|!|?|" & vbNullChar & "|" & vbNull & "|" & vbCr & "|" & vbLf & "|" & vbCrLf & "|¤|ö|Ö|í|é|´|| ||||‘|’|¥|||||||| ||||"
tmp = Split(s, "|")

'MsgBox Chr(34)

For i = 0 To UBound(tmp)
With myExportstruct
    .album = Trim(Replace(.album, tmp(i), ""))
    .artist = Trim(Replace(.artist, tmp(i), ""))
    .file = Trim(Replace(.file, tmp(i), ""))
    .genre = Trim(Replace(.genre, tmp(i), ""))
    .track = Trim(Replace(.track, tmp(i), ""))
    .year = Trim(Replace(.year, tmp(i), ""))
    .Comment = Trim(Replace(.Comment, tmp(i), ""))
    .Bitrate = Trim(Replace(.Bitrate, tmp(i), ""))
End With
'Debug.Print tmp(i) & "   " & Asc(tmp(i))
Next

End Sub
0
Comment
Question by:gerrymcd
3 Comments
 
LVL 26

Expert Comment

by:EDDYKT
ID: 12318487
can you just check with printable character?

0x20 – 0x7E
0
 
LVL 32

Accepted Solution

by:
Erick37 earned 75 total points
ID: 12318608
You could use the brute force method of removing non-printable characters...  Chr(10) and Chr(13) (vbCRLF) are not affected.

Dim sStr As String
Dim i As Long

For i = 1 To 9
    sStr = Replace(sStr, Chr(i), "")
Next

For i = 11 To 12
    sStr = Replace(sStr, Chr(i), "")
Next

For i = 14 To 31
    sStr = Replace(sStr, Chr(i), "")
Next
0
 
LVL 16

Expert Comment

by:jimbobmcgee
ID: 12318726
You may find

    tmp = Array(vbCrLf, Chr(27), Chr(0))

is a quicker way to write your array (so long as tmp() is a variant, not a string).

As for the actual question, perhaps you should create an array of the characters that are allowed as I am sure there will be far more that are not (thanks to unicode, etc).

Alternatively, how about checking the strings with a LIKE operator:  http://www.devx.com/vb2themax/Tip/18578 has more details...

HTH

J.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to debug this code 7 65
SLMGR Switches Are Not Working On KMS Host 3 137
Visual Studio 2005 text editor 10 47
pop out of webbrowser1 control vba6 5 41
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question