javascript - React Native - 我如何以粗体字重分享消息?
问题描述
我正在使用 react native Share API,我想以粗体字重分享一条消息我似乎找不到办法做到这一点有谁知道如何做到这一点?
解决方案
我还没有找到任何关于共享粗体文本的信息,但您可以在此处使用 Unicode 字符中已分配的粗体字符:
https://unicode.org/charts/nameslist/n_1D400.html
我使用此方法制作了将字符转换为粗体的函数:
const toBold = text =>{
const charSet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '!', '?', '.', ',', '"', "'"];
const targetCharSet = ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '❗', '❓', '.', ',', '"', "'"];
const textArray = text.split('');
let boldText = '';
textArray.forEach((letter) => {
const index = charSet.findIndex((_letter) => _letter === letter);
if (index !== -1) {
boldText = boldText + targetCharSet[index];
} else {
boldText = boldText + letter;
}
});
return boldText;
}
用法:
toBold('Hi Mom');
输出:
注意: 文本可能不会显示在您的控制台中。
推荐阅读
- android - Fragment$Companion 无法在 BottomNavigationView 侦听器上强制转换为 androidx.fragment.app.Fragment
- php - laravel morphable 获取源码
- android - 触发 AppBar 回到其在 CoordinatorLayout 内的正常位置
- c - Unix中的fork函数
- iis - ASP.NET Core 3 - 有没有办法将模块部分添加到生成的 Web 配置文件
- javascript - 如何在 MVC 模式中创建模型类的实例 - SapUI5
- php - 如何修复内存耗尽的postgresql
- ios - RxSwift 不同库崩溃`NSInternalInconsistencyException`
- python - Python:如何将要处理的对象成员(可能嵌套更深)传递给函数?
- javascript - JQuery Calculator:无法让运算符工作