Solved

unescape in vb6

Posted on 2004-04-29
12
2,135 Views
Last Modified: 2012-05-04
Hi

How do I unescape a html formatted string (escaped in vbscript ) in vb.

or can some one pls suggest a better way of doing this:

I've a html formatted string that I've to store in a database and then open it in vb and print to text file for further processing.

Since storing html in database with all the quotes & spl characters and then reading it in vb gives error, I'm trying to escape the string before storing and then in VB I'm trying to unescape before printing.

Thanks
ak

0
Comment
Question by:ak3103
  • 6
  • 6
12 Comments
 

Author Comment

by:ak3103
ID: 10949780
Also rt now I've a simple VB function  that converts hex to string, but does not work for many characters defined in html

Function unescape(ByVal s As String)
If s = "" Then
    unescape = ""
    Exit Function
End If
If Mid(s, 1, 1) <> "%" Then
    unescape = s
    Exit Function
End If
b = Split(s, "%")
For Each ele In b
    If ele <> "" Then
        a = Mid(ele, 1, 2)
        out = out & Chr(CInt("&H" & a)) & Mid(ele, 3)
    End If
Next
unescape = out
End Function

0
 
LVL 4

Expert Comment

by:Javin007
ID: 10949838
"Since storing html in database with all the quotes & spl characters and then reading it in vb gives error, I'm trying to escape the string before storing and then in VB I'm trying to unescape before printing."

What kinds of errors are you getting and when?  Sounds like the best option would be to just fix those errors.

-Javin
0
 

Author Comment

by:ak3103
ID: 10949946
if the html has dbl quotes then reading and using the string in VB gives errors
with single quotes stroing in the database itself is givng errors - this is easy to solve.

But HTML has got somany wierd characters, So I exactly dont know when I'll get an error - So I thought the best option is to escape and unescape - that way I can be sure that whatever is entered will be stored and retrieved with no probs

thanks
ak
0
 
LVL 4

Accepted Solution

by:
Javin007 earned 200 total points
ID: 10951912
I'm still not sure what you mean by "escape and unescape"

But give me an example of EXACTLY what you're trying to do?  Sounds like it's as simple as dumping a single string of data to a database, then exporting it to a text file.  This should be VERY easy, regardless of what characters are used.

-Javin
0
 

Author Comment

by:ak3103
ID: 10952436
Hey Javin

are you familiar with vbscript/javascript escape/unescape functions? these are built into the languages. -- not that u dont know, but the way u asked sounded like that.

escape function takes as input a html string and converts all the spl characters (except letters and digits) to 2 digit & 4digit hex form so that the html string would not contain any special chars like quotes etc.  

and unescape takes the encoded string and generates the html from it.

this is done when passing a html string between various functions/pages etc.  Now the string I obtain is from a rich text editor. so it has html in it.

the text file I'm writing also contains some other html. so if i dont escape and unescape, and if the html string I'm trying to write to the file has some extra html tags in it, ithose tags interfer with the tags in the main html file and the resulting html file is screwed up. to avoid this and also to avoid the mess with dbl quotes & single quotes when handling the strings I'm trying to do the escape/unescape.

ak

0
 
LVL 4

Expert Comment

by:Javin007
ID: 10952583
Hrm.  Still not following.  I need an example of what you have, and what you want to do with it.  An actual example.  And I don't know much about HTML scripting, so I'm not familiar with the escape/unescape function.  But I do know VB very well.

-Javin
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.

 

Author Comment

by:ak3103
ID: 10952801
here's an example

<hTML><TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><font style=" font-size:'12px';color:'#000000';"  face='Arial'></FONT></P></TEXTFORMAT><TEXTFORMAT LEADING="2">

is converted into the foll  string when escaped  , the %3c etc are hex code for < symbol and so on

%3ChTML%3E%3CTEXTFORMAT%20LEADING%3D%222%22%3E%3CP%20ALIGN%3D
%22LEFT%22%3E%3Cfont%20style%3D%22%20font-size%3A%2712px%27%3Bcolor
%3A%27%23000000%27%3B%22%20%20face%3D%27Arial%27%20%3E%3C/FONT
%3E%3C/P%3E%3C/TEXTFORMAT%3E%3CTEXTFORMAT%20LEADING%3D%222%22
%3E%3

as you can see the string contains <html> tag at the beginning. so if i write this into another file containing html already, the file is screwed up.

and also the initial html string there are dbl quotes and single quotes. when I read the string like this or try to write to database, it'll give an error.

so I'm converting the original string into the 2nd string (escape) and then writing into the database.

but then I've to convert the 2nd string into the first string (unescape) before wirting into the text file.

to escape/unescape there are built in functions in asp, but not in VB. so I'm tryiing to find if there is a function. the first function I posted works fine if there are 2digit hex codes. but if there is a 4digit hex code, it is giving an error.

ak



0
 
LVL 4

Expert Comment

by:Javin007
ID: 10953094
Okay, I now see what the escape/unescape thing does, but what kind of database is this that it's giving you an error when you try to put the data into it?  You should have no problem parsing out the <HTML> tag with a simple string=mid$(string, 7)
Then dumping this:
<TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><font style=" font-size:'12px';color:'#000000';"  face='Arial'></FONT></P></TEXTFORMAT><TEXTFORMAT LEADING="2">

Into a databse shouldn't give you any trouble at all.  You could then retrieve the data from the database, and dump that to a text file.  I'm still not catching why you're using the escape/unescaping?  Am I missing something, or do you need to know how to dump the text into the database?

-Javin
0
 

Author Comment

by:ak3103
ID: 10953207
hey Javin ,

" or do you need to know how to dump the text into the database?"  :)

its not the database that will give an error when putting <html>,  but the actual file into which I'm trying to write the string.
also the <html> tag is just an example. any tag  will give an error in the output file if it not correctly placed.
so the usual process to avoid this is by escaping the html string and then unescaping the string wherever it has to be displayed.

I found some unescape functions but all of them were giving errors, So just trying to find if anyone knew a better function. If this doesnt work out, then I'll try manipulating the strings (escaping single & dbl quotes etc)

ak
0
 
LVL 4

Expert Comment

by:Javin007
ID: 10953379
AHhhhhhhhhhhhhhhhhhh... I think I finally get it...
When you output this to the other file, (an HTML file) you want the HTML file to DISPLAY THE TEXT of the HTML?

-Javin
0
 

Author Comment

by:ak3103
ID: 10959689
Hey Javin

yeah, sort of like that
anyways, I'll take care of it later. not so urgent rt now. thx for the help

ak
0
 
LVL 4

Expert Comment

by:Javin007
ID: 10966144
Sorry I couldn't do more.  :/  Ask a moderator to remove the question so you get your points back.

-Javin
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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

914 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

19 Experts available now in Live!

Get 1:1 Help Now