【问题标题】:Trouble displaying % symbol on Android when sharing from RN app从 RN 应用程序共享时,无法在 Android 上显示 % 符号
【发布时间】:2019-08-24 15:40:05
【问题描述】:

My React Native 应用可让人们通过消息与朋友分享折扣。消息在应用程序中被硬编码:

const message = 'Get 10% off!'
Linking.openURL(`sms:? &body=${message}`)

在 Android 上,% 符号未正确解释,如下所示:

% o 变成了这个奇怪的问号。

我尝试用各种 Unicode 替换 %,将其转义 \%%,或者将其设置为大写,但没有任何效果。

我应该如何编码 % 以使其在 Android 上按预期呈现?

【问题讨论】:

    标签: android react-native unicode


    【解决方案1】:

    您可以尝试符号 % 的 HTML 代码:

    <Text>
        &#10140;
    <Text>
    

    这应该可行,但要小心:

    <Text>
        {'&#10140;'}
    <Text>
    

    这样不行

    【讨论】:

      【解决方案2】:

      对要通过链接发送的每个参数使用encodeURIComponent(),以正确编码任何特殊字符。

      const message = encodeURIComponent('Get 10% off!')
      Linking.openURL(`sms:? &body=${message}`)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-03-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-26
        • 2018-06-18
        • 2020-01-01
        相关资源
        最近更新 更多