var split

Dear all ,
I use this
.split(lineSeperator);

Open in new window

to split based on passed variable from user input, its work fine , but when user use '\n'
for new line its not working as expected.
ethar1Asked:
Who is Participating?
 
Rainer JeschorConnect With a Mentor Commented:
Hi,
it works if you create a new regexp based on the input variable like:
function RunSplit() {
    var teststring = 'Hello\nWorld';
    var sep = new RegExp($('#mysplit').val());
    $('#result').html(teststring.split(sep).join("|"));
}

Open in new window


See example here:
http://jsfiddle.net/EE_RainerJ/JcDDd/

HTH
Rainer
0
 
Kevin CrossChief Technology OfficerCommented:
Often what you have is carriage return, then line feed.
\r\n

Open in new window


Therefore, make sure the character is indeed a newline versus a carriage return as well as not both.
0
 
ethar1Author Commented:
yes its  a new line
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
ethar1Author Commented:
even \r\n don't work
0
 
ethar1Author Commented:
btw, when I use
.split('\n');

Open in new window


its work fine...
0
 
käµfm³d 👽Commented:
I think this is why your previous question showed the optional carriage return ( \r? ). The standard line terminator under Windows is carriage-return/line-feed ( \r\n ). Not everyone follows this, though. Sometimes you have to make either optional in order to match against target data. In your case, I think you are looking for the optional carriage return, so I would modify your example to:

.split('\r?\n');

Open in new window

0
 
Sar1973Commented:
In HTML it's <br>; otherwise, try to use vbCrlf instead of the text \n.
0
 
ethar1Author Commented:
none work,
its not html
@ Rainer Jescho, I have the data in text box
0
 
käµfm³d 👽Commented:
Can you attach a sample of the text as a file so that we can see what you are working with?
0
 
ethar1Author Commented:
0
 
ethar1Author Commented:
Rainer Jeschor, could you please explain why?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.