Solved

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

Posted on 2006-11-07
9
346 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
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 14

Expert Comment

by:B_Dorsey
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 54

Expert Comment

by:b0lsc0tt
Comment Utility
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 11

Author Comment

by:Andrew Angell
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
@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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

763 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now