...

View Full Version : Regular Expression for new line



dragon6158
06-10-2008, 07:18 PM
Hello,
I am trying to split:



|Version|Date|Author|Changes
1.0|5/5/2008|David Kisley|Initial Issue
1.0|5/5/2008|David Kisley|Initial Issue
1.0|5/5/2008|David Kisley|Initial Issue
1.0|5/5/2008|David Kisley|Initial Issue


into separate lines split on the new line 'character' at the end of each line and put the lines into an array for further processing. Does anybody have any idea how to split these in the new line 'character'? Thank you.

Don

Arty Effem
06-11-2008, 02:05 AM
into separate lines split on the new line 'character' at the end of each line and put the lines into an array for further processing. Does anybody have any idea how to split these in the new line 'character'?

Try str.split(/\n\r?/);

dragon6158
06-11-2008, 10:14 PM
Unfortunately it didn't work. I can split the lines if I wrap them in <pre> tags but if I use <table> tags, it won't split the lines. I am trying to dynamically build a table using the data that looks like the example and if I could do the split in the <table> tag it would be the best way. I can build the rows but not the table yet. Thanks.

rnd me
06-11-2008, 11:13 PM
post the code to build rows, and we can finish it.

rnd me
06-11-2008, 11:15 PM
Try str.split(/\n\r?/);

i think that your regExp should actually be /\r?\n/g

Philip M
06-12-2008, 08:15 AM
Does this help?


<script type = "text/javascript">

var x = "1.0|5/5/2008|David Kisley|Initial Issue 1.0|5/5/2008|David Kisley|Initial Issue 1.0|5/5/2008|David Kisley|Initial Issue 1.0|5/5/2008|David Kisley|Initial Issue"

x = x.replace(/Issue /gi, "Issue\n");
alert (x);
x = x.split("\n");
alert (x[0]);
alert (x[1]);

</script>

EDIT: Perhaps not, unless the final word in each entry is "issue". I am not very clear why all four entries are the same, or where they are coming from.


When trouble arises and things look bad, there is always one individual who perceives a solution and is willing to take command. Very often, that individual is crazy.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum