• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 357
  • Last Modified:

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!
0
Andrew Angell
Asked:
Andrew Angell
  • 4
  • 2
  • 2
  • +1
1 Solution
 
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
 
b0lsc0ttCommented:
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
 
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
b0lsc0ttCommented:
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 AngellAuthor 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
 
b0lsc0ttCommented:
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
 
Andrew AngellAuthor 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
 
b0lsc0ttCommented:
@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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

  • 4
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now