【问题标题】:How to print first sentence from semicolon separated string? [duplicate]如何从分号分隔的字符串中打印第一句话? [复制]
【发布时间】:2022-11-15 19:26:36
【问题描述】:

我在数据库表中有一列,其中保存类型字符串。它保存由分号分隔的多行,就像这样 -

this is first sentence;this is second sentence;this is third sentence

我只想打印第一行,即 -

this is first sentence

知道如何使用 JavaScript 实现吗?

【问题讨论】:

    标签: javascript


    【解决方案1】:

    使用String.prototype.split

    const string ='this is first sentence;this is second sentence;this is third sentence'
    const sentences = string.split(';')
    const first = sentences[0]
    console.log(first)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-26
      • 1970-01-01
      相关资源
      最近更新 更多