T
T
TRUEC0DER2022-03-10 11:37:13
typescript
TRUEC0DER, 2022-03-10 11:37:13

How to replace text before dash in a string?

There is a line:
"The first message before the dash is the first message after the dash. The second message before the dash is the second message after the dash. The third message before the dash is the third message after the dash"

How can I change all the text before the dash? (Let's put it in an HTML tag)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2022-03-10
@TRUEC0DER

Here is an option when the message is in an array. How to achieve this, I think it should not be very difficult.

const messages = [
    "Первое сообщение до тире - первое сообщение после тире",
    "Второе сообщение до тире - второе сообщение после тире",
    "Третье сообщение до тире - третье сообщение после тире"
]

for (let m of messages) {
    const message = `
<div>
    <span>${m.split(' - ')[0]}</span>
    <em>${m.split(' - ')[1]}</em>
</div>`
console.log(message)
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question