Solved

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

Posted on 2006-11-07
9
347 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
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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
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…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

943 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

17 Experts available now in Live!

Get 1:1 Help Now