Справочник по C#

    Исходники по языку программирования CSharp

    Конвертируем BBCode в HTML: Справочник по C#

    /
    /
    /
    24 Views


    public string ConvertBBCodeToHTML (string str)
    {
    Regex exp;
    // format the bold tags: [b][/b]
    // becomes: 
    exp = new Regex(@"[b](.+?)[/b]");
    str = exp.Replace(str, "$1");
    
    // format the italic tags: [i][/i]
    // becomes: 
    exp = new Regex(@"[i](.+?)[/i]");
    str = exp.Replace(str, "$1");
    
    // format the underline tags: [u][/u]
    // becomes: 
    exp = new Regex(@"[u](.+?)[/u]");
    str = exp.Replace(str, "$1");
    
    // format the strike tags: [s][/s]
    // becomes: 
    exp = new Regex(@"[s](.+?)[/s]");
    str = exp.Replace(str, "$1");
    
    // format the url tags: [url=www.website.com]my site[/url]
    // becomes: my site
    exp = new Regex(@"[url=([^]]+)]([^]]+)[/url]");
    str = exp.Replace(str, "$2");
    
    // format the img tags: [img]images/image.jpeg[/img]
    // becomes: 
    exp = new Regex(@"[img]([^]]+)[/img]");
    str = exp.Replace(str, "");
    
    // format img tags with alt: [img=images/image.jpeg]this is the alt text[/img]
    // becomes:
    exp = new Regex(@"[img=([^]]+)]([^]]+)[/img]");
    str = exp.Replace(str, "");
    
    //format the colour tags: [color=red][/color]
    // becomes: 
    // supports UK English and US English spelling of colour/color
    exp = new Regex(@"[color=([^]]+)]([^]]+)[/color]");
    str = exp.Replace(str, "$2");
    exp = new Regex(@"[colour=([^]]+)]([^]]+)[/colour]");
    str = exp.Replace(str, "$2");
    
    // format the size tags: [size=3][/size]
    // becomes: 
    exp = new Regex(@"[size=([^]]+)]([^]]+)[/size]");
    str = exp.Replace(str, "$2");
    
    // lastly, replace any new line characters with
    
    str = str.Replace("rn", "
    rn");
    
    return str;
    }
    

    Конвертируем BBCode в HTML: Справочник по C#

    0.00 (0%) 0 votes

    moyadcode13
    • Facebook
    • Twitter
    • Google+
    • Linkedin
    • Pinterest
    moyadcode10
    moyadcode11
    moyadcode9