zoukankan      html  css  js  c++  java
  • C#使用for循环移除HTML标记

    public static string StripTagsCharArray(string source)
    {
    char[] array = new char[source.Length];
    int arrayIndex = 0;
    bool inside = false;
    for (int i = 0; i < source.Length; i++)
    {
    char let = source[i];
    if (let == '<')
    {
    inside = true;
    continue;
    }
    if (let == '>')
    {
    inside = false;
    continue;
    }
    if (!inside)
    {
    array[arrayIndex] = let;
    arrayIndex++;
    }
    }
    return new string(array, 0, arrayIndex);
    }
    }
     
    using System;
    using System.Text.RegularExpressions;
    class Program
    {
    static void Main()
    {
    const string html = "<p>There was a <b>.NET</b> programmer " +
    "and he stripped the <i>HTML</i> tags.</p>";
    Console.WriteLine(HtmlRemoval.StripTagsCharArray(html));
    }
    }
  • 相关阅读:
    BZOJ1087=Codevs2451=洛谷P1896&P2326互不侵犯
    poj1286
    P1066 2^k进制数
    开车旅行
    洛谷P1396 营救
    poj1840
    poj3693
    poj1195
    3955 最长严格上升子序列(加强版)
    1021 玛丽卡
  • 原文地址:https://www.cnblogs.com/sjqq/p/6813194.html
Copyright © 2011-2022 走看看