0

I'm retreiving data from a texfile with AJAX through:

document.getElementById("my div").innerHTML=xmlhttp.responseText;

but I want to make a linebreak in the text before each capital letter starts. How do I go about doing that? Appreciate the help.

3
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by Taywin
0

You are sure about a line break before each capital letter, right? Maybe you can try...

var str = xmlhttp.responseText;
str = str.replace(/([A-Z])/g, "<br />$1")
document.getElementById("my_div").innerHTML = str

edit: syntax error... No need to have semicolon unless you want to compact the code.

Edited by Taywin: n/a

0

Except for line 2 I agree. Line 2 should be

str = str.replace(/([A-Z])/g, "<br />$1");

. I tested it with this string ('Hello there Mark, how is it Going.') and got this displayed.
Hello there
Mark, how is it
Going.

0

After you use match() function, you would get an array in return if the substring is found. The $1 represents the selected sub string you want to match inside a pair of parenthesis. If you have 2 pairs, the second pair is represent by $2 and so on.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.