在删除一个ASP“新线” [英] Removing a 'New Line' in ASP

查看:80
本文介绍了在删除一个ASP“新线”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何从一个字符串的开头取出一个新行?

发生的事情是,我一直在控制和调试别人的PHP code,并将之转化为ASP。他所做的是把html标签在数据库表,并简单地附和他们。当然,一个字段包含像&LT HTML表格标签; THEAD> < TBODY> < TR> ,等我不想继续错这样做我所做的就是先开启来控制它们< TR> s转换< BR /> s和去除一切。但问题是,第一个< TR> 使得字符串的最开始一个新行。我想删除它。另一个问题是,并非所有的领域里面有标签htmlt,所以我必须把东西一样,如果text.substring(0,1)=(IDK要放什么东西在这里),然后(也许是更换或修剪此功能)。任何帮助吗?

下面是一个示例字段内容。 pretty讨厌确实

 <表格的宽度=705HEIGHT =323ID =渐变式总结=会议结果>
      <&THEAD GT;
        &所述; TR>
          < TD WIDTH =238>产品与LT; / TD>
          < TD WIDTH =610> TS2360磁带和LT; BR />
          驱动防爆preSS< / TD>
        < / TR>
      < / THEAD>
      <&TBODY GT;
        &所述; TR>
          < TD>机/模型,HVEC< / TD>
          < TD> 3580< BR />
          S63,3580S6X< / TD>
        < / TR>
        &所述; TR>
          < TD>产品优势和LT; / TD>
          < TD>多O / S< BR />
            加密和放大器;放大器;媒体< BR />
            分区能够< BR />
            LTFS支持< / TD>
        < / TR>
       < / TBODY>
    < /表>

这样做后,< TR> s转换< BR> 和删除其他HTML标记,输出beacame:

 产品TS2360磁带驱动器前preSS
给背景颜色的表格单元实现无缝过渡
机/模型,HVEC 3580 S63,3580S6X
产品优势多O / S加密和放大器;放大器;媒体分区能够支持LTFS

(据说跳过一条线产品之前,因为它有< TR> 之前,但没有在该块报价显示)

先谢谢了。


解决方案

  VAR cleanedFieldValue = someValueWithLineBreaks.TrimStart('\\ n');

在VB.NET版本可能是这样的:

 暗淡cleanedFieldValue = someValueWithLineBreaks.TrimStart(ControlChars.Lf)

修改

听起来好像你正在试图解析一些HTML,然后做它的工作。我会建议使用的Html敏捷性包的为和阅读试图使用<一的罪恶href=\"http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454\">RegEx解析你的HTML 。

How do i remove a new line from the start of a string?

what's happening is that i've been controlling and debugging someone else's php code, and converting it into asp. what he did was put html tags in a db table, and simply echoing them. ex, a field contains html table tags like <thead>,<tbody>,<tr>, etc. i didn't want to continue the wrong doing so what i did was to control them by first turning <tr>s into <br />s, and removing everything else. but problem is that the first <tr> makes a new line in the very start of the string. i want to remove it. another problem is that not all fields has htmlt tags inside, so i have to put something like if text.substring(0,1)="(idk what to put here)" then (maybe the replace or trim functions here). any help please?

here's a sample field content. pretty nasty indeed:

    <table width="705" height="323" id="gradient-style" summary="Meeting Results">
      <thead>
        <tr>
          <td width="238">Product</td>
          <td width="610">TS2360 Tape<br />
          Drive Express</td>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>Machine/model, HVEC</td>
          <td>3580<br />
          S63, 3580S6X</td>
        </tr>
        <tr>
          <td>Product strengths</td>
          <td>Multi O/S<br />
            Encryption &amp; media<br />
            partition capable<br />
            LTFS support</td>
        </tr>
       </tbody>
    </table>

so after making <tr>s into <br>s and removing other html tags, output beacame:

Product TS2360 Tape Drive Express 
Give background color to the table cells to achieve seamless transition 
Machine/model, HVEC 3580 S63, 3580S6X 
Product strengths Multi O/S Encryption &amp; media partition capable LTFS support

(supposedly skipping a line before "Product" because it has <tr> before it, but didn't show in the block quote)

Thanks in advance.

解决方案

var cleanedFieldValue = someValueWithLineBreaks.TrimStart( '\n' );

The VB.NET version might look like:

Dim cleanedFieldValue = someValueWithLineBreaks.TrimStart(ControlChars.Lf)

Edit

It sounds as if you are trying to parse some Html and then do work on it. I would recommend using the Html Agility Pack for that and read about the evils of attempting to use RegEx to parse your Html.

这篇关于在删除一个ASP“新线”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆