Solved

Function to Replace Certain UNICODE chars

Posted on 2004-08-11
7
1,634 Views
Last Modified: 2012-06-21
I need a function to replace the unicode quotes from a string to standard quotes (") and also unicode single quotes.  Here is how I might have done it in ASP:

<%
' convert all types of single quotes
tmpString = replace(tmpString, chr(145), chr(39))
tmpString = replace(tmpString, chr(146), chr(39))

' convert all types of double quotes
tmpString = replace(tmpString, chr(147), chr(34))
tmpString = replace(tmpString, chr(148), chr(34))
%>

How can I do this in C#/ASP.NET?
0
Comment
Question by:hendridm
[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
  • 3
7 Comments
 
LVL 24

Expert Comment

by:Justin_W
ID: 11775160
Since C# is case-sensitive, use this:
   ' convert all types of single quotes
   tmpString = tmpString.Replace(Chr(145), Chr(39));
   tmpString = tmpString.Replace(Chr(146), Chr(39));

   ' convert all types of double quotes
   tmpString = tmpString.Replace(Chr(147), Chr(34));
   tmpString = tmpString.Replace(Chr(148), Chr(34));

Note that since the Chr function is a VB function, you might have to also include something like this:
   using Mucrosoft.VisualBasic;
0
 
LVL 24

Expert Comment

by:Justin_W
ID: 11775167
I meant:
   using Microsoft.VisualBasic;
0
 
LVL 8

Author Comment

by:hendridm
ID: 11775184
Is there a native C# way to do it?
0
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
LVL 24

Accepted Solution

by:
Justin_W earned 300 total points
ID: 11775339
Sure.  You can declare Char variables like this:
   char MyChar = 'X';        // Character literal
   char MyChar = '\x0058';   // Hexadecimal
   char MyChar = (char)88;   // Cast from integral type
   char MyChar = '\u0058';   // Unicode

E.g., if your Char variables are called c34, c39, and c145-c148, then do:
   ' convert all types of single quotes
   tmpString = tmpString.Replace(c145, c39);
   tmpString = tmpString.Replace(c146, c39);

   ' convert all types of double quotes
   tmpString = tmpString.Replace(c147, c34);
   tmpString = tmpString.Replace(c148, c34);
0
 
LVL 8

Author Comment

by:hendridm
ID: 11775538
I can't figure out the code for “ and ”.

I tried \u0147 but it displays some funky character.
Response.Write("\u0147");

Where can I find the codes?  I tried Google w/o success.
0
 
LVL 8

Author Comment

by:hendridm
ID: 11775553
nm, I found them here:
http://www.cl.cam.ac.uk/~mgk25/ucs/quotes.html

Thanks...
0
 
LVL 8

Author Comment

by:hendridm
ID: 11776088
For the record, in case someone else stumbles across this PAQ in the future, here is eventually what I used:

    private string StipUnicode(string s)
    {
      // convert all types of single quotes
      s=s.Replace("\u2018", "&#39;"); // left single quotation mark
      s=s.Replace("\u2019", "&#39;"); // right single quotation mark
      s=s.Replace("'", "&#39;"); // single quotes

      // convert all types of double quotes
      s=s.Replace("\u201C", "&quot;"); // left double quotation mark
      s=s.Replace("\u201D", "&quot;"); // right double quotation mark
      
      //replace carriage returns & line feeds
      s=s.Replace("\n", "");
      s=s.Replace("\r", "");
      
      return s.Trim();
    }
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

630 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