Any Javascript gurus?

Talk about anything here. Post lifespan is 1 year.

Postby haven on Fri Jun 01, 2018 9:34 am

I don't usually need to use javascript for work but a new add-on requires it sometimes.

If I have the following string

String1|String2|String3|String4

How do I remove everything up to and including the second pipe so I'm left with just String3|String4?

String1 and 2 are variable lengths so I can't just define a set number to cut.
User avatar
haven
Art Expert
 
Status: Active
Posts: 5119
Joined: Thu May 29, 2003 12:00 am

Postby golobulus on Fri Jun 01, 2018 3:09 pm

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split

Use split to split the string using the "|" characters and then grab the last 2 elements of the returned list.
User avatar
golobulus
Art Expert
 
Status: Active
Posts: 1957
Joined: Sun Oct 16, 2011 10:47 pm
Location: Queen Creek, AZ

Postby haven on Fri Jun 01, 2018 4:49 pm

Thanks man, I'll give that a shot.
User avatar
haven
Art Expert
 
Status: Active
Posts: 5119
Joined: Thu May 29, 2003 12:00 am


Return to Anything Goes



Who is online

Users browsing this forum: HairyHood, ifonly216 and 8 guests