How to clean crazy characters from a string value..?? I don't know what character it is!

I've got a script that's used to post auctions to eBay.  The product description is often copied/pasted from 3rd party web sites and many times includes some kind of crazy character that ends up being a square in code view.  The most recent example I came across was a simple text paragraph when in design view of Dreamweaver looked perfectly normal.  However, if I go into code view I see 2 squares where 2 spaces would normally be.  The squares aren't there for every space in code view, just a couple of areas.

The squares (whatever character they are) cause XML parsing errors when the script tries to post the item to eBay.  We remove the squares and then it works fine.  I'd like to figure out a way to automate the removal of these things using Replace but since I don't know what character they are I can't figure out what to do.  

Any information would be greatly appreciated.  Thanks!
LVL 11
Andrew AngellCo-Owner / DeveloperAsked:
Who is Participating?
 
b0lsc0ttConnect With a Mentor IT ManagerCommented:
That means that the character is the Ascii character 11 which corresponds to the Home key.  Is this some string that should be unicode or some other format?  Do you know what that character should be?

If not, and you just want to get rid of the symbol then do a replace.  Replace Asc(11) with a space (e.g. " ").

If you want to try to preserve the characters and have the browser translate them correctly then you may need to specify the encoding in the head section of the html.  Your browser will default to a character encoding but it can be changed and then the browser will understand characters better.  The key is to find the proper encoding if you think this is the issue.

Let me know how this helps or if you have questions.
0
 
B_DorseyCommented:
Could you do a regular expression to check for characters you want to allow, and remove the ones that arent in your ok list?

0
 
b0lsc0ttIT ManagerCommented:
angelleye,

Have you tried using Server.HtmlEncode?

There was a question here where an expert posted a block of code like the one below.  It will go through each character in a string, etc and print the Ascii value.  I have found it very useful in cases like this.  If I can find the question or the expert I will give credit but it seems like it was deleted.  The block of code below is how I have used it.  Let me know if you have a question about using it.

Dim i
For i = 1 to Len(strTest)
   Response.Write Asc(Mid(strTest, i, 1)) & "[" & Mid(strTest, i, 1) & "], "
Next

Let me know if you have any questions or need more information.

b0lsc0tt
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
fruhjCommented:
if it's the same char each time, you can print the ascii code for it, then use that code in your replace statement (replace(char(99), "")

my asp is a bit rusty, but you get the idea..

to find the char - either load it in a hex editor,
or from your page
do something like
for i = 1 to 100
  response.write mid(i,1,badstring) & "=" & (ascii(mid(i,1,badstring)) & "<br>"
next

this should print the first 100 chars like this
a=97
p=112
p=112
l=108
e=101
 =32  (note 32=space)
[]=your number

again the ASP is a bit rusty so you may need to look up the syntax of the commands, but this should give you an approach to find the char and eliminate it.
0
 
b0lsc0ttIT ManagerCommented:
The modified code originally came from a comment by expert Acperkins in a question that now has been deleted.  I can definitely help you with it if you have questions but wanted to give some credit.

bol
0
 
Andrew AngellCo-Owner / DeveloperAuthor Commented:
Ok, here's what I ran:

probString = " "

Dim i
For i = 1 to Len(probString)
   Response.Write Asc(Mid(probString, i, 1)) & "[" & Mid(probString, i, 1) & "], "
Next

And here's what I end up with:

11[ ], 11[ ],

So I'm still a little lost....????

0
 
Andrew AngellCo-Owner / DeveloperAuthor Commented:
Yeah I just need to get rid of the thing so I'm using the Replace function.  I'll just have to refer back to this if I ever get it for another character.  Thanks!
0
 
fruhjCommented:
hey B0lsc0tt -

  Just noticed that I had posted right after you did - we probably typed our answers at about the same time - didn't mean to jump on your post - and I'm glad you got the well deserved points.

- Jack
0
 
b0lsc0ttIT ManagerCommented:
@Jack - I noticed that and no problem.  Thanks for the post though.

@AngelEye - Your welcome!  I'm glad that I could help you.  It is a handy bit of code to keep available, especially if you don't have access to a hex editor program.  Thank you for the grade, the points and the fun question.

bol
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.