代码之家  ›  专栏  ›  技术社区  ›  Anu

如何从react native中的html内容中删除空格?

  •  0
  • Anu  · 技术社区  · 6 年前

    在我的项目中,我使用 WebView 当然是本地人。但问题是我在结果中得到了不想要的字符。我的意思是html内容包含 &nbsp 它们在react native中呈现为一些不需要的字符和文本。我试过了 regex 移除,但不起作用。以下是我的代码,请帮忙。

    密码

    <Content contentContainerStyle={{ flex: 1}}>
         {this.state.data.map(item =>
           <View style={{flex:1,padding:10}}>
            <Text style={{textAlign:'center', margin:15,fontSize:20,fontWeight:'bold'}}>{item.data.course.name}</Text>
            <WebView
            source={{ html: item.data.description.replace(/^\s*&nbsp;/m, '') + htmlStyle }}
            javaScriptEnabled={true}
             />
             </View>
             )}
          </Content>
    

    以下是截图

    enter image description here

    json

    data:
    course: {id: 5506, name: "Balance of Payment Account: Meaning and Significance"}
    curriculum: false
    description: "<p style="text-align: justify;"><strong>Guide to the module: </strong></p>↵<p style="text-align: justify;">              This module deals with the balance of payment account concepts from the Indian context. At the later part, a typical balance of payment scenario of India is illustrated by taking 2012-13 financial year as an example.</p>↵<p style="text-align: justify;"><strong>Balance of payment account</strong></p>↵<p style="text-align: justify;">           Balance of payment systematically shows the whole types of economic engagement between residents of India and the residents of the rest of the world. The transaction details are usually shown for a period (like one year). 
    
    0 回复  |  直到 6 年前