gpt4 book ai didi

java - java中将一个字符串转换为另一个字符串

转载 作者:行者123 更新时间:2023-12-01 07:35:15 26 4
gpt4 key购买 nike

如何转换#title<h1>title</h1>在java中?我正在尝试创建一种算法将 markdown 格式转换为 html 格式。

最佳答案

如果你想创建 Markdown 算法,请查找正则表达式。

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

回答评论 - 有关字符类的更多信息 here :

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

关于java - java中将一个字符串转换为另一个字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13001259/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com