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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:14:27+00:00 2026-05-17T00:14:27+00:00

My Problem is for particular case occurring in my project. In my Html document,

  • 0

My Problem is for particular case occurring in my project.

In my Html document,
I want to
replace <td> with <td class=”right”> for all tds except first one in a <tr> tag. (if there is <tr> inside a <tr> tag then that also needs to be handled).

If input is like:

<tr>
  <td>1</td>
  <td>2</td>
  <td>3</td>
<tr>

output should be like:

<tr>
  <td>1</td>
  <td class=”right”>2</td>
  <td class=”right”>3</td>
<tr>

I have tried..this code..

public static string tableFormat(string html)   // Add extra attribute to td
        {
            int start = 0, end = 0, trstart = 0, trend = 0;
           // html = CleanUpXHTML(html);  // clean unnecessary p tags
            while (html.Contains("<tr>"))
            {
                //start=end;
                trstart = html.IndexOf("<tr>", end);
                if (trstart == -1)
                    break;
                trend = html.IndexOf("</tr>", trstart);
                start = html.IndexOf("<td>", trstart);
                end = html.IndexOf("</td>", trend);
                while (end < trend)
                {

                    start = html.IndexOf("<td>", end);
                    html = html.Insert(start + 3, " class=\"right\"");
                    end = html.IndexOf("</td>", trstart);

                }
            }
            return html;
        }
  • 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-17T00:14:27+00:00Added an answer on May 17, 2026 at 12:14 am

    just call this function from main:
    Note:this code will work for valid html i.e xhtml

     public static string TableFormat(string xhtml)
        {
            int start = 0, end = 0, trstart = 0, trend = 0;
    
            while (trstart != -1)
            {
                //start=end;
                trstart = xhtml.IndexOf("<tr>", end);
                if (trstart == -1)
                    break;
                trend = xhtml.IndexOf("</tr>", trstart);
                start = xhtml.IndexOf("<td>", trstart);
                end = xhtml.IndexOf("</td>", start);
                while (end < trend)
                {
                    //int trackTr = 0;
                    start = xhtml.IndexOf("<td>", end);
                    if (start > trend)
                        break;
                    xhtml = xhtml.Insert(start + 3, " class=\"right\"");
    
                    end = xhtml.IndexOf("</td>", start);
    
                }
            }
            return (xhtml);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The problem I'm facing is that I'm trying to manipulate (in this particular case
My particular problem: I have a string which specifies an aribitrary type in a
I have a problem downloading particular file types by WebClient. So there are no
I need to profile my JAVA SRC code for some particular problem I am
I'm creating a blog engine as a learning exercise and one particular problem has
Problem: I have two spreadsheets that each serve different purposes but contain one particular
i have this problem to find a particular xml node l have post this
Problem description: Read an xml file, traverse to a particular node (element), if it
I'm having a problem getting XCode to deal with a particular file structure that
I have a problem using the Java search function in Eclipse on a particular

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.