交互式愛情
2023-08-24 17:58:49
所以我的后端返回一個帶有兩組強(qiáng)標(biāo)簽的字符串。好像:const string = "<strong>Name N.</strong> How are you doing today? <strong>more text</strong>"由于我使用的是 React Native,因此無法按原樣顯示。我想返回看起來像這樣的東西:<Text> <Text style={{fontWeight: 'bold'}>Name N.</Text> How are you doing today? <Text style={{fontWeight: 'bold'}>more text</Text><Text>解決這個問題的最佳方法是什么?
1 回答

鳳凰求蠱
TA貢獻(xiàn)1825條經(jīng)驗(yàn) 獲得超4個贊
你可以用兩種方式做到這一點(diǎn)
第一個選項(xiàng)
通過網(wǎng)絡(luò)視圖
const string = "<strong>Name N.</strong> How are you doing today? <strong>more text</strong>"
<WebView source={{html: string}} />
第二個選項(xiàng)
通過替換和拆分
const text = "<strong>Name N.</strong> How are you doing today? <strong>more text</strong>";
const [first, second, third] = text.replace(/(<\/strong>|<strong>)/g, '|').split('|').filter(cur => cur).map(cur => cur.trim());
console.log(first);
console.log(second);
console.log(third);
添加回答
舉報
0/150
提交
取消