473,403 Members | 2,293 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

How to replace unicode characters with their HTML codes.

I have a file path that contains unicode characters.
e.g: "C:\vs2003\OutputDir???\mc_data\"
I want to translate this string to HTML with unicode characters:
e.g: "C:\vs2003\OutputDirאבג\data\"

I tried
strPath = System.Web.HttpUtility.HtmlEncode(strPath)
but it did not work.

I suppose I can create bytes from strPath and if I get (ascii > 127)
then replace "charVal" with "&charVal;"
but I am looking for a function that already does this algorithm...

any suggestions?
Thanks,
Atara

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #1
1 3431
I found it in C# in http://conceptdev.blogspot.com/
Here is the vb code I use:

' --------------------------------------------------------
Private Function mcHtmlEntityEncode(ByVal unicodeText As String) As
String
' based on http://conceptdev.blogspot.com/
' ----------------------------------------------------
Dim unicodeVal As Integer
Dim encoded As String = ""
Dim c As Char

For Each c In unicodeText
unicodeVal = AscW(c) 'unicodeVal = c
Debug.WriteLine(c.ToString & " : " & unicodeVal.ToString)
If ((unicodeVal >= 49) And (unicodeVal <= 122)) Then
' in 'ascii' range x30 to x7a which is 0-9A-Za-z plus some
punctuation
encoded += c ' leave as-is
Else
' outside 'ascii' range - encode
encoded += String.Concat("&#",
unicodeVal.ToString(System.Globalization.NumberFor matInfo.InvariantInfo)
, ";")
End If
Next
Return encoded
End Function
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Nicolas Bouillon | last post by:
Hi I would like to replace accentuel chars (like "é", "è" or "à") with non accetued ones ("é" -> "e", "è" -> "e", "à" -> "a"). I have tried string.replace method, but it seems dislike...
48
by: Zenobia | last post by:
Recently I was editing a document in GoLive 6. I like GoLive because it has some nice features such as: * rewrite source code * check syntax * global search & replace (through several files at...
8
by: Eric Lilja | last post by:
Hello, I had what I thought was normal text-file and I needed to locate a string matching a certain pattern in that file and, if found, replace that string. I thought this would be simple but I had...
11
by: Patrick Van Esch | last post by:
Hello, I have the following problem of principle: in writing HTML pages containing ancient greek, there are two possibilities: one is to write the unicode characters directly (encoded as two...
32
by: Wolfgang Draxinger | last post by:
I understand that it is perfectly possible to store UTF-8 strings in a std::string, however doing so can cause some implicaions. E.g. you can't count the amount of characters by length() | size()....
14
by: Etu | last post by:
Hi, I have a string: string c = "'abc' \"cde\", 'mno' \"xyz\","; how can I use the c.Replace(???, ???) method to have this string: "'abc' "cde", 'mno' "xyz"," that is, all the...
0
by: Atara | last post by:
I have a file path that contains unicode characters. e.g: "C:\vs2003\OutputDir???\mc_data\" I want to translate this string to HTML with unicode characters: e.g: "C:\vs2003\OutputDirאבג\data\" ...
2
by: Mike Labosh | last post by:
I need to determine if a string contains double-byte (unicode) characters. In SQL, it was easy. Cast it from NVARCHAR to VARCHAR and back again, and see if it got lossage. But in VB.NET, all...
2
by: Frantic | last post by:
I'm working on a list of japaneese entities that contain the entity, the unicode hexadecimal code and the xml/sgml entity used for that entity. A unicode document is read into the program, then the...
7
by: 7stud | last post by:
Based on this example and the error: ----- u_str = u"abc\u9999" print u_str UnicodeEncodeError: 'ascii' codec can't encode character u'\u9999' in position 3: ordinal not in range(128) ------
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.