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 9203991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:36:03+00:00 2026-06-17T23:36:03+00:00

I have a string: <div class=className1234><p>Some html</p></div> From this string, I would like to

  • 0

I have a string:

<div class="className1234"><p>Some html</p></div>

From this string, I would like to get <p>Some html</p> i.e. I would like to remove the surrounding div tags based on the fact that it’s class contains ‘className’.

What I’ve Tried

What I’ve tried works, but it’s cludgey – and I know there’ll be a better alternative like regex or something. What I currently do is chain a series of substring(), indexof() and replace() calls to strip out the divs.

EDIT: I’ve used the phrase ‘innerhtml’ because I’d like to think there’s a library out there somewhere that would allow me to manipulate a string with regard to the tags within it.

PLEASE NOTE: There’s no JQuery involved in this. It’s all server-side C#.
(See tags)

  • 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-06-17T23:36:04+00:00Added an answer on June 17, 2026 at 11:36 pm

    How about:

    XmlDocument doc = new XmlDocument();
    doc.LoadXml(divStr);
    // classAtr will be null if the root is not a div with a class with the value className1234
    XmlNode classAtr = doc.SelectSingleNode("/div/@class[contains(., 'className1234')]");
    string result = classAtr != null ? doc.DocumentElement.InnerXml : divStr;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string contaning some html markup, like this: var html = <div>
I have a String variable say strHTML = <div class='abc'> This is a test
I have string that look like Array that fetched from other webservice like this
I have a HTML document (string) which contains a div with the class foo:
I have this elements: <div class=ELEMENT_LISTY style=> <div class=TITLE id=174>string</div> <div class=BUTTONY> <div class=POGLAD></div>
Assuming I have HTML similar to this: <div class=fooContainer> <div class=barContainer> <a href=#>foo-bar</a> </div>
I have this HTML code: <div class =lvlone> <div class = lvltwo> Hello <span>World</span>
I have a string having this form : <div class=c1>text1</div></br> <div class=c2>text2</div></br> <div class=c3>text3</div></br>
I have this following class: public class TV { public string GroupId { get;
I have some code like @{ string result = <div> text </div><br />; }

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.