细胞.内部HTML没有得到正确的方式


protected void ReadHtmlTable(string patientName, string startHour, string startMinute, int rowspan)
            {
                 for(int i = 0; i <= tableAppointment.Rows.Count - 1; i++)
                    {
                        for(int j = 0; j <= tableAppointment.Rows[i].Cells.Count - 1; j++)
                        {
                            if(tableAppointment.Rows[i].Cells[j].InnerHtml.Trim() == startHour)
                            {
                                if(tableAppointment.Rows[i].Cells[j + 1].InnerHtml.Trim()== startMinute)
                                {
                                    tableAppointment.Rows[i].Cells[j + 2].InnerText = patientName;
                                    tableAppointment.Rows[i].Cells[j + 2].RowSpan = rowspan;
                                    tableAppointment.Rows[i].Cells[j + 2].Style.Add("color", "green");
                                    tableAppointment.Rows[i].Cells[j + 2].Style.Add("background", "green");
                                }
                            }
                        }
                    }
        }

上面的代码是我的服务器端代码,它在OnSaveStateComplete(EventArgs e)事件上执行。 我正在用 C# 阅读我的 HTML 表。 当我检查它的第一个单元格第二个单元格文本时,它给出的结果是这样的"\r\t\t\t08:00\r\t\t\t"。我最后使用了修剪,但没有工作。

试试这个

string str = "rnttttttttt08:00rntttttttt".Trim('t', 'r', 'n');

你应该能够用正则表达式从那里出来 RegEx.Replace(tableAppointment.Rows[i].Cells[j + 1].InnerHtml, "\s+", "");

MSDN 的 Regex.Replace 方法。 那里的例子也有处理空格。

最新更新