【问题标题】:How can I make the text line break whenever there is a dot at the end of the text?每当文本末尾有一个点时,如何使文本换行?
【发布时间】:2022-08-18 17:29:32
【问题描述】:

我在名为 mainStory 的数据库中的状态中包含文本。 mainStory 值是从后端加载并存储在状态中的值。

mainStory = \"hello mr musk. have you ever seen the movie looks completely diffrent from its add?. this is so weird.\"

我想在渲染的末尾有一个点时换行

我应该怎么办?下面是我的代码。

    const SecondStoryContainer = styled.View`

    `;

    const CardMainTxt = styled.Text`
    `;

    const App = () => {
    const [mainStory, setMainStory] = useState(\'\');


    <SecondStoryContainer>
    <CardMainTxt>
    {mainStory}
    </CardMainTxt>
    </SecondStoryContainer>

    }

    标签: reactjs react-native


    【解决方案1】:

    这是js中的例子,你可以这样使用,它有效!

    const myString = 'Hello, this is a string with one line. It will soon have 2 lines.'
    const stringWithNewLines = myString.replaceAll('. ', '.\n');
    console.log(stringWithNewLines)

    【讨论】:

      猜你喜欢
      • 2013-04-05
      • 1970-01-01
      • 2012-07-03
      • 2014-05-29
      • 1970-01-01
      • 1970-01-01
      • 2014-11-13
      • 1970-01-01
      • 2017-12-07
      相关资源
      最近更新 更多