split not working if pass split character as variable

Dear all,
Please take a look at this code:

split function not working as expected  if passed as parameter

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

in your example \n is \\n and NOT the new line character.
You may...should use a regular expression to achieve your goal : http://jsfiddle.net/aA45X/

function RunSplit(sep, data) {
    sep = new RegExp(sep);
    var items = data.replace("(?m)^[ \t]*\r?\n", "");
    var lines = items.replace(/,$/, "").split(sep);
    $('#result').text( lines.length );

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ethar1Author Commented:
could you please explain "in your example \n is \\n and NOT the new line character"

\ is the escape character when you're using it in a string in your code :
var str = "_______\n_______"; // here \n is a single character

but in textbox, you type two characters : \ followed by n
the \ is not the escape character
Get Blueprints for Increased Customer Retention

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

ethar1Author Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.