简体   繁体   English

上标React-Native文本

[英]Superscript React-Native text

In my React-Native app I would like to add superscript(exponent) in text. 在我的React-Native应用程序中,我想在文本中添加上标(指数)。

For example, 例如,

I have this text: Here's a new product called test^123. 我有这段文字:这是一个名为test ^ 123的新产品。 This product can do ... 该产品可以做...

So in this example ^123 is the superscript(exponent) 因此,在此示例中,^ 123是上标(指数)

I have try a lot of thing but I can not fix the problem because every time the text start on another line. 我已经尝试了很多事情,但是由于每次文本都在另一行开始时,我无法解决问题。

Do anyone have any idea how to solve this? 有谁知道如何解决这个问题?

Thanks! 谢谢!

You can insert the unicode value of the superscript characters you require. 您可以插入所需的上标字符的unicode值。 See the table here for which unicode values to use. 请参阅此处的表以了解要使用哪些unicode值。 To insert these values into the text you wish to display, use the format \\uXXXX in the string you wish to display. 要将这些值插入要显示的文本中,请在要显示的字符串中使用格式\\ uXXXX。 In your given example the string would be 'test\¹\²\³'. 在给定的示例中,字符串为“ test \\ u00B9 \\ u00B2 \\ u00B3”。

If you need to build these superscript strings dynamically you will need a simple mapping function that receives the standard digits and returns the unicode values. 如果需要动态构建这些上标字符串,则需要一个简单的映射函数,该函数接收标准数字并返回unicode值。

If you prefer to be more literal in your code, you can also insert the unicode characters right there in the string - provided your file is encoded as UTF-8. 如果您希望在代码中使用更多文字,也可以在字符串中的右边插入unicode字符-只要您的文件编码为UTF-8。 For this, you can copy the characters from another source or see this post , for example. 为此,您可以从其他来源复制字符或例如查看此帖子 A similar mapping function could be made for this approach too. 也可以为这种方法提供类似的映射功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM