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

  • Home
  • SEARCH
  • 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 8302259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:14:31+00:00 2026-06-08T17:14:31+00:00

Given an HTML document, I want to identify all the numbers in the document

  • 0

Given an HTML document, I want to identify all the numbers in the document and add custom tags around the numbers.
Right now, i use the following:

HtmlNodeCollection bodyNode = htmlDoc.DocumentNode.SelectNodes("//body");
MatchCollection numbersColl = Regex.Matches(htmlNode.InnerText, <some regex>);

Once I get the numbersColl, I can traverse through each Match and get the index.
However, I can’t change the InnerText since it is read-only.
What I need is that if match.Value = 100 and match.Index=25, I want to replace that 25 with
<span isIdentified='true'> 25 </span>

Any help on this will be greatly appreciated. Currently, since I am not able to modify the inner text, I have to modify the InnerHtml but some element might have 25 in it’s innerHtml. That should not be touched. But how do I identify whether the number is within
an html tag i.e. < table border=’1′ > has 1 in the tag.

  • 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-08T17:14:32+00:00Added an answer on June 8, 2026 at 5:14 pm

    Here’s what I did to work around the read-only property limitation of the InnerText property of a Text node, just select the Parent node of the Text node and note the index of the Text node in the child node collections of the Parent node. Then just do a ReplaceChild(...).

           private void WriteText(HtmlNode node, string text)
            {
                if (node.ChildNodes.Count > 0)
                {
                    node.ReplaceChild(htmlDocument.CreateTextNode(text), node.ChildNodes.First());
                }
                else
                {
                    node.AppendChild(htmlDocument.CreateTextNode(text));
                }
            }
    

    In your case I believe you need to create a new Element node that wraps the text into an HtmlElement and then just use it as a replacement of the Text node.

    Or even better, see if you can do something like the answer posted here:
    Replacing a HTML div InnerText tag using HTML Agility Pack

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

Sidebar

Related Questions

Given an HTML document in Nokogiri, I want to remove all <p> nodes with
Basically, I would like to decode a given HTML document, and replace all special
Given the HTML below, I am trying to use jQuery to match all the
Given the following HTML code, why is it that when this document is printed
Given a document like this: <html xmlns=http://www.w3.org/1999/xhtml xml:lang=de> <body> ... </body> How can I
I have a necessity to sort a given HTML table of the following structure,
Given an HTML like following: ...more html above... <div class=any_name> <p>Element A goes here</p>
Given an HTML page I would like to get all the 'x' files that
I want to remove the end tag of a given HTML string. I get
Given the following HTML: <!doctype html> <html> <body> <span style=background-color: blue;> Some text here

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.