Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6572141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:58:08+00:00 2026-05-25T14:58:08+00:00

I am trying to few junk characters in my string using the following statement:

  • 0

I am trying to few junk characters in my string using the following statement:

desc = string.replace(desc,'“','"')
desc = string.replace(desc,'”','"')
desc = string.replace(desc,'·','.') 

Can I write the above 3 statements in to a single statement or atlease the 1st two statements to a single statement.

I can not use any third-party libraries in my project.

Edit @unutbu:
My String looks like below:

This is '“' my teststring '”'. I want to replace unicode with appropriate HTML not the whole string only with unicode values.

After using the code:

import HTMLParser

text='“ ” ·'
parser=HTMLParser.HTMLParser()
desc=parser.unescape(text)

I am getting only the HTML equivalents , not the string. But I just want to replace the appropriate values keeping everything in Original String.

I expect the out put as below:

This is “my teststring”. I want to replace unicode with appropriate HTML not the whole string only with unicode values.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T14:58:09+00:00Added an answer on May 25, 2026 at 2:58 pm

    HTMLParser is in the standard library:

    import HTMLParser
    
    text='“ ” ·'
    parser=HTMLParser.HTMLParser()
    desc=parser.unescape(text)
    print(desc)
    # “ ” ·
    

    If you want that in a single statement, you could of course do

    desc=HTMLParser.HTMLParser().unescape(text)
    

    but that might not be an advantage if you need to call unescape in more than one place, and in general, chaining calls like this makes it harder to identify where exceptions occur.

    Note that HTMLParser.unescape will unescape all HTML entities defined in htmlentitydefs.names2codepoint (plus ').


    Edit: HTMLParser.unescape returns different characters than what you posted.
    To get exactly those characters, you might use xml.sax.saxutils:

    text='“ ” ·'
    import xml.sax.saxutils as saxutils
    print(saxutils.unescape(text,{'“':'"', '”':'"', '·':'.', }))
    # " " .
    

    Note that saxutils.unescape also replaces <, > and &. If you wish to replace only “, ”, and &middot, then I’d use aix’s answer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've spent a few days trying to figure this one out and can't seem
Hai, I am trying to understand few concepts in JavaScript. Consider the following code:
am trying to read few lines from a txt file using JS,and i have
I am trying to understand few things about using dylib and still studying, so
I am trying to plot few points dynamically on my Custom View using Quartz
I'm trying a few different approaches to Javascript inheritance at the moment. I have
It seems I am one of the few trying to get Mono's mod_mono to
I was playing around with Python's subprocess module, trying a few examples but I
I've been trying this a few different ways, but I'm reaching the conclusion that
I've been for the past few hours trying to figure out why openCV doesn't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.