473,548 Members | 2,633 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Removing obscure chars

Hi All

I have an ASP function in place to strip invalid chars out of a data store
before I create an XML file of this data, but my function doesn't work on a
certain set of chars.

As far as I can see these are the following:

a) trademark char
b) long hyphen/dash char
c) smart/curly quotes (both left and right)

Even though my function is set up as follows:

Function ReFormatStringF orXML(s)
IF LEN(s) 0 AND NOT IsNull(s) THEN
s = Replace(s,"™"," ™")
s = Replace(s,"—","-")
s = Replace(s,"’"," "")
s = Replace(s,"'"," "")
s = Replace(s,"""", """)
s = Replace(s,"&"," &")
s = Replace(s,"<"," &lt;")
s = Replace(s,">"," &gt;")
END IF
ReFormatStringF orXML = s
End Function

These chars still pass by and foul up my XML file.

I have a feeling that its down to the fact that my function is looking for
the html equiv rather than the actual char, but I can't possibly get away
with simply copy and pasting these friggin(!!) chars into my function.
Surely this is bad practise?

Does anybody know how I can trap and replace/remove these chars if need be?

Thanks

Apr 3 '07 #1
3 5650
Gazing into my crystal ball I observed "Yobbo" <in**@NoSpamIt. com>
writing in news:ug******** ******@TK2MSFTN GP05.phx.gbl:
Hi All

I have an ASP function in place to strip invalid chars out of a data
store before I create an XML file of this data, but my function
doesn't work on a certain set of chars.

As far as I can see these are the following:

a) trademark char
b) long hyphen/dash char
c) smart/curly quotes (both left and right)
I detest these "smart" quotes. Are regular quotes dumb by comparison?
>
Even though my function is set up as follows:

Function ReFormatStringF orXML(s)
IF LEN(s) 0 AND NOT IsNull(s) THEN
s = Replace(s,"™"," &trade;")
s = Replace(s,"—","-")
s = Replace(s,"’"," &quot;")
s = Replace(s,"'"," &quot;")
s = Replace(s,"""", "&quot;")
s = Replace(s,"&"," &amp;")
s = Replace(s,"<"," &lt;")
s = Replace(s,">"," &gt;")
END IF
ReFormatStringF orXML = s
End Function

These chars still pass by and foul up my XML file.

I have a feeling that its down to the fact that my function is looking
for the html equiv rather than the actual char, but I can't possibly
get away with simply copy and pasting these friggin(!!) chars into my
function. Surely this is bad practise?
You are putting in the HTML entity, you may need to put the ascii
character instead, for example:
s = replace(s,chr(6 0),"&gt;")
>
Does anybody know how I can trap and replace/remove these chars if
need be?

Thanks

HTH

--
Adrienne Boswell at Home
Arbpen Web Site Design Services
http://www.cavalcade-of-coding.info
Please respond to the group so others can share

Apr 4 '07 #2
Yobbo wrote on Tue, 3 Apr 2007 18:17:59 +0100:
Hi All

I have an ASP function in place to strip invalid chars out of a data store
before I create an XML file of this data, but my function doesn't work on
a certain set of chars.

As far as I can see these are the following:

a) trademark char
b) long hyphen/dash char
c) smart/curly quotes (both left and right)

Even though my function is set up as follows:

Function ReFormatStringF orXML(s)
IF LEN(s) 0 AND NOT IsNull(s) THEN
s = Replace(s,"™"," &trade;")
s = Replace(s,"—","-")
s = Replace(s,"’"," &quot;")
s = Replace(s,"'"," &quot;")
s = Replace(s,"""", "&quot;")
s = Replace(s,"&"," &amp;")
s = Replace(s,"<"," &lt;")
s = Replace(s,">"," &gt;")
END IF
ReFormatStringF orXML = s
End Function

These chars still pass by and foul up my XML file.

I have a feeling that its down to the fact that my function is looking for
the html equiv rather than the actual char, but I can't possibly get away
with simply copy and pasting these friggin(!!) chars into my function.
Surely this is bad practise?

Does anybody know how I can trap and replace/remove these chars if need
be?
Your function is quite limited. What happens when a character not in your
list appears? The XML supported entity list is pretty small.

Here's the function I use in my own XML generation code, it's crude but it works:

function XMLEncode(strTe xt)

'loop through code and replace all non-alphanumeric characters with their
ascii value
strNewText = ""

For i = 1 to Len(strText)

j = Asc(Mid(strText ,i,1))

If j = 10 Then
'replace tab with a line break
strNewText= strNewText & "&lt;br&gt; "
ElseIf j = 13 or j = 9 then 'cr, lf, tab
'strip them
ElseIf j = 34 then
strNewText = strNewText & "&quot;"
ElseIf j = 39 then
strNewText = strNewText & "&apos;"
ElseIf j = 32 or j = 45 or (j >=49 and j <= 57) or (j >=65 and j <= 90) or
(j >= 97 and j <= 122) then
'ok
strNewText = strNewText & Mid(strText,i,1 )
ElseIf j = 38 Then '&
strNewText = strNewText & "&amp;"
ElseIf j = 60 then '<
strNewText = strNewText & "&lt;"
ElseIf j = 62 then '>
strNewText = strNewText & "&gt;"
Else
strNewText = strNewText & "&#" & j & ";"
End If

Next

XMLEncode = strNewText
End Function
This checks each character in the string in turn, and replaces some with
entities, and the rest of the non-printable characters with their numeric
value. You could easily add a few more entity replacements as required. Just
watch out for the first couple of replacements where I replace tabs with a
<br>, and strip out carriage returns and line feeds, as that might not fit
what you want do with the XML yourself.

Dan
Apr 4 '07 #3

"Yobbo" <in**@NoSpamIt. comwrote in message
news:ug******** ******@TK2MSFTN GP05.phx.gbl...
Hi All

I have an ASP function in place to strip invalid chars out of a data store
before I create an XML file of this data, but my function doesn't work on
a
certain set of chars.

As far as I can see these are the following:

a) trademark char
b) long hyphen/dash char
c) smart/curly quotes (both left and right)

Even though my function is set up as follows:

Function ReFormatStringF orXML(s)
IF LEN(s) 0 AND NOT IsNull(s) THEN
s = Replace(s,"™"," &trade;")
s = Replace(s,"—","-")
s = Replace(s,"’"," &quot;")
s = Replace(s,"'"," &quot;")
s = Replace(s,"""", "&quot;")
s = Replace(s,"&"," &amp;")
s = Replace(s,"<"," &lt;")
s = Replace(s,">"," &gt;")
END IF
ReFormatStringF orXML = s
End Function

These chars still pass by and foul up my XML file.

I have a feeling that its down to the fact that my function is looking for
the html equiv rather than the actual char, but I can't possibly get away
with simply copy and pasting these friggin(!!) chars into my function.
Surely this is bad practise?

Does anybody know how I can trap and replace/remove these chars if need
be?
>
Thanks
If you are creating an XML file can you use a DOMDocument to build it and
save it?
That'll ensure correct XML is created.

Apr 5 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1670
by: Ryan | last post by:
hi i am having a problem with a php script i am trying to write. the problem is that the ouput from the script (the html) was sometimes being truncated, but sometimes it would work as expected. i managed to narrow the problem down (believe it or not) to the difference between a sinle character anywhere in the script.
6
2960
by: Aaron Collins | last post by:
Hello, i have a string that was entered in a web form and stored in a mysql database where the user entered carriage returns as well as <br>'s after each line in the form. the data is stored as line 1<br> line 2<br> line 3
10
2742
by: Tom Szabo | last post by:
Hi All, Just wondering there is any other way to remove the toolbar from the browser than using " ...toolbar=no ..." in the window.open(...)
2
15863
by: matt | last post by:
I have an upload script for a photo and a caption. It all goes pear shaped when I upload a character like ' " or / \ | Is there anyway I can parse through the filename when submitting the form and remove any illegal characters like this??? Thanks in advance Matt
7
1577
by: A.M. Kuchling | last post by:
python.org has a page of "Python vs. X" language comparisons at <http://www.python.org/doc/Comparisons.html>. They're all pretty outdated, and often unfair because they're written by a person who knows Python well but has only a nodding acquaintance with language X. I'm planning to drop this page from python.org because it's so outdated and...
6
2507
by: Batista, Facundo | last post by:
I'm doing a small program, in which the user will have the option to enter his/her password everytime, or just save it (to a file). So, is there a module to obscure the password text in a secure way? I can't hash it (with md5 or something), because I not need to compare the password the user enters with a previous one. I need to restore...
6
8625
by: bruce | last post by:
hi... i'm running into a problem where i'm seeing non-ascii chars in the parsing i'm doing. in looking through various docs, i can't find functions to remove/restrict strings to valid ascii chars. i'm assuming python has something like valid_str = strip(invalid_str)
17
2691
by: Eric_Dexter | last post by:
def simplecsdtoorc(filename): file = open(filename,"r") alllines = file.read_until("</CsInstruments>") pattern1 = re.compile("</") orcfilename = filename + "orc" for line in alllines: if not pattern1 print >>orcfilename, line I am pretty sure my code isn't close to what I want. I need to be able
0
444
by: Yobbo | last post by:
Hi All I have an ASP function in place to strip invalid chars out of a data store before I create an XML file of this data, but my function doesn't work on a certain set of chars. As far as I can see these are the following: a) trademark char b) long hyphen/dash char
3
3448
by: MLH | last post by:
Back in mid-2003, lucason posted a question about removing punctuation chars from a string. Suggested code was posted using Replace function. Could the FN below be easily modified for use with A97 which has no replace FN? xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx lucason View profile
0
7512
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7438
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7707
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7951
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
5362
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5082
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3495
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3475
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
751
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.