var split

Posted on 2013-12-26
Medium Priority
Last Modified: 2013-12-28
Dear all ,
I use this

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.
Question by:ethar1
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 60

Expert Comment

by:Kevin Cross
ID: 39740387
Often what you have is carriage return, then line feed.

Open in new window

Therefore, make sure the character is indeed a newline versus a carriage return as well as not both.

Author Comment

ID: 39740398
yes its  a new line

Author Comment

ID: 39740420
even \r\n don't work
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 39740426
btw, when I use

Open in new window

its work fine...
LVL 75

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:


Open in new window

LVL 44

Accepted Solution

Rainer Jeschor earned 2000 total points
ID: 39740487
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());

Open in new window

See example here:


Expert Comment

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

Author Comment

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

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?

Author Comment

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

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…
Suggested Courses

765 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