Help splitting a string up

I have a a Javascript variable that is coming back with a special delimited string.  (It's how SharePoint stores multiple values).

I'm initializing my Javascript variable like this:

var sponsor=$(this).attr("ows_Sponsor");
if(sponsor==null)
sponsor='';

Open in new window


My values are coming back like these.

;#SG3;#ACC;#

Open in new window

or
;#SG3;#ACC;#AETC;#

Open in new window


How can I spit the strings up so they look more like this?

SG3,ACC

Open in new window

or
SG3,ACC,AETC

Open in new window


Thank you.
greddinAsked:
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.

Julian HansenCommented:
You can split the strings into an array or into comma separated string like this
// INPUT STRING
var s = ';#SG3;#ACC;#AETC;#';
// REMOVE LEADING AND  TRAILING DELIMITERS
s = s.replace(/^;#|;#$/g,'');
// ARRAY OPTION
var arr = s.split(';#');
console.log(arr);
// CSV OPTION
var csv = s.replace(/;#/g ,',');
console.log(csv);

Open in new window

Output
 ["SG3", "ACC", "AETC"]
SG3,ACC,AETC

Open in new window

0

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
greddinAuthor Commented:
Thank you Julian.  Worked great!
0
Julian HansenCommented:
You are welcome.
0
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
JavaScript

From novice to tech pro — start learning today.

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.