Convert BBCode to HTML

 

http://www.dreamincode.net/code/snippet2661.htm

/*
* A method to convert BBCode to HTML
* Author: Danny Battison
* Contact: gabehabe@googlemail.com
*/

/// <summary>
/// A method to convert basic BBCode to HTML
/// </summary>
/// <param name="str">A string formatted in BBCode</param>
/// <returns>The HTML representation of the BBCode string</returns>
public string ConvertBBCodeToHTML (string str)
{
Regex exp;
// format the bold tags: [b][/b]
// becomes: <strong></strong>
exp = new Regex(@"\[b\](.+?)\[/b\]");
str = exp.Replace(str, "<strong>$1</strong>");

// format the italic tags: [i][/i]
// becomes: <em></em>
exp = new Regex(@"\[i\](.+?)\[/i\]");
str = exp.Replace(str, "<em>$1</em>");

// format the underline tags: [u][/u]
// becomes: <u></u>
exp = new Regex(@"\[u\](.+?)\[/u\]");
str = exp.Replace(str, "<u>$1</u>");

// format the strike tags: [s][/s]
// becomes: <strike></strike>
exp = new Regex(@"\[s\](.+?)\[/s\]");
str = exp.Replace(str, "<strike>$1</strike>");

// format the url tags: [url=www.website.com]my site[/url]
// becomes: <a href="www.website.com">my site</a>
exp = new Regex(@"\[url\=([^\]]+)\]([^\]]+)\[/url\]");
str = exp.Replace(str, "<a href=\"$1\">$2</a>");

// format the img tags: [img]www.website.com/img/image.jpeg[/img]
// becomes: <img src="www.website.com/img/image.jpeg" />
exp = new Regex(@"\[img\]([^\]]+)\[/img\]");
str = exp.Replace(str, "<img src=\"$1\" />");

// format img tags with alt: [img=www.website.com/img/image.jpeg]this is the alt text[/img]
// becomes: <img src="www.website.com/img/image.jpeg" alt="this is the alt text" />
exp = new Regex(@"\[img\=([^\]]+)\]([^\]]+)\[/img\]");
str = exp.Replace(str, "<img src=\"$1\" alt=\"$2\" />");

//format the colour tags: [color=red][/color]
// becomes: <font color="red"></font>
// supports UK English and US English spelling of colour/color
exp = new Regex(@"\[color\=([^\]]+)\]([^\]]+)\[/color\]");
str = exp.Replace(str, "<font color=\"$1\">$2</font>");
exp = new Regex(@"\[colour\=([^\]]+)\]([^\]]+)\[/colour\]");
str = exp.Replace(str, "<font color=\"$1\">$2</font>");

// format the size tags: [size=3][/size]
// becomes: <font size="+3"></font>
exp = new Regex(@"\[size\=([^\]]+)\]([^\]]+)\[/size\]");
str = exp.Replace(str, "<font size=\"+$1\">$2</font>");

// lastly, replace any new line characters with <br />
str = str.Replace("\r\n", "<br />\r\n");

return str;
}

转载于:https://www.cnblogs.com/daoxuebao/archive/2012/05/16/2503496.html

经过网络搜索和信息整合,以下是关于“40s-s2 IT相关含义”的解答: --- ### 关于“40s-s2”在IT领域的可能含义 1. **时间延迟标识** 在某些系统配置文件或脚本中,“40s”可以表示40秒的时间间隔。“s2”则可能是第二个阶段或者第二步的缩写。这种组合常见于定时任务、服务启动顺序或状态检查机制中。 2. **版本控制标记** “40s-s2”也可能是一种内部版本号命名规则的一部分。例如,在软件发过程中,团队可能会用类似的方式标注特定功能模块的状态更新(如第40次迭代后的子阶段2)。 3. **错误代码或日志标签** 如果出现在服务器日志或其他技术文档里,“40s-s2”也许代表某种异常情况下的响应时间阈值超出警告。具体需要结合上下文查看其定义范围是否匹配实际业务需求。 4. **硬件设备参数描述** 对于嵌入式系统而言,该字符串还能够用来说明某款产品的工作周期设定为四十秒钟并且处于二级运行模式下工作等情况之中 。 5. **算法性能指标** 若是在讨论优化方案时提及此术语,则大概率涉及到程序执行效率评估方面的话题 。比如某个排序函数完成一百万个元素排列所需耗时不高于四十分之一秒即满足条件等情形均可纳入此类别考虑范畴之内 。 --- 为了进一步明确这个短语的具体意义,请提供更多背景资料以便准确判断。 --- ### 示例代码解析 假设这是一个简单的 Python 定时器实现案例,其中包含了类似的逻辑结构: ```python import time def stage_timer(stage_name, duration): print(f"Starting {stage_name} for {duration} seconds...") time.sleep(duration) print(f"{stage_name} completed.") if __name__ == "__main__": # Example usage based on "40s-s2" stage_timer("Stage S2", 40) # Simulates a process lasting 40 seconds in Stage S2. ``` ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值