Solved

var split

Posted on 2013-12-26
11
234 Views
Last Modified: 2013-12-28
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.
0
Comment
Question by:ethar1
11 Comments
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 39740387
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
 

Author Comment

by:ethar1
ID: 39740398
yes its  a new line
0
 

Author Comment

by:ethar1
ID: 39740420
even \r\n don't work
0
 

Author Comment

by:ethar1
ID: 39740426
btw, when I use
.split('\n');

Open in new window


its work fine...
0
 
LVL 74

Expert Comment

by:käµfm³d 👽
ID: 39740475
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 44

Accepted Solution

by:
Rainer Jeschor earned 500 total points
ID: 39740487
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
 
LVL 9

Expert Comment

by:Sar1973
ID: 39742066
In HTML it's <br>; otherwise, try to use vbCrlf instead of the text \n.
0
 

Author Comment

by:ethar1
ID: 39742835
none work,
its not html
@ Rainer Jescho, I have the data in text box
0
 
LVL 74

Expert Comment

by:käµfm³d 👽
ID: 39742858
Can you attach a sample of the text as a file so that we can see what you are working with?
0
 

Author Comment

by:ethar1
ID: 39743516
0
 

Author Comment

by:ethar1
ID: 39744182
Rainer Jeschor, could you please explain why?
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now