Replace all occurence in qml string

Viewed 1669

I am trying to replace all occurrences of line breaks to html line breaks in my string, but it is only converting the first one found

var output= "";
string x = "Hi\nMy name is x\nAnd age is 10\n";
output = x
output = output.replace("\\n", "<br>")

Output =

Hi
My name is x\nAnd age is 10\n
1 Answers

QML is just a very feeble front end to JavaScript. You need to use the JavaScript global option.

str.replace(/blue/g, "red");

In your case that would be:

output = output.replace("\\n/g", "<br>")
Related