Solved

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

Posted on 2006-11-07
9
352 Views
Last Modified: 2013-12-03
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
Comment
Question by:Andrew Angell
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 14

Expert Comment

by:B_Dorsey
ID: 17891543
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
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 17891559
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
 
LVL 12

Expert Comment

by:fruhj
ID: 17891573
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!

 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 17891649
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
 
LVL 11

Author Comment

by:Andrew Angell
ID: 17892273
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
 
LVL 54

Accepted Solution

by:
b0lsc0tt earned 250 total points
ID: 17892332
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
 
LVL 11

Author Comment

by:Andrew Angell
ID: 17892587
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
 
LVL 12

Expert Comment

by:fruhj
ID: 17892818
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
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 17893296
@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: 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

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

688 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