在java中将字符串转换为另一个字符串 [英] Convert a string to another one in java

查看:29
本文介绍了在java中将字符串转换为另一个字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在java中将#title转换为

title

?我正在尝试创建一种算法来将 Markdown 格式转换为 html 格式.

How do I convert #title to <h1>title</h1> in java? I'm trying to create an algorithm to convert markdown format to html format.

推荐答案

如果你想创建 Markdown 算法寻找正则表达式.

If you want to create markdown algorithm look for regular expression.

String noHtml = "#title1";
String html = noHtml.replaceAll("#(.+)", "<h1>$1</h1>");

评论答案 - 有关字符类的更多信息此处:

answer to comment - more about character classes here:

String noHtml = "#title1";
String html = noHtml.replaceAll("#([a-zA-Z]+)", "<h1>$1</h1>");

这篇关于在java中将字符串转换为另一个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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