Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Separatorless Split 4

Status
Not open for further replies.

MarkZK

Technical User
Jul 13, 2006
202
GB
Hello,

How would I split/joined a string without a separator ?, for example, if I know the string will always be six random numbers long (var string = "124356";) but I needed to send it through a function to return the same string with partions (splitS(string); returns "12|43|56"). which is the best way to approach this. ?

Thanks for any advice/help.
 
feherke, nice solution. Can you explain the \B, I see that it prevents the | on the end of the string but do not understand why. My solution was a 2 part process:
Code:
str.replace(/(.{2})/g, "$1|").replace(/\|$/, "")
But your code alleviates the need for the 2nd replace, I just can't figure out why.

-kaht

Looking for a puppy? [small](Silky Terriers are hypoallergenic dogs that make great indoor pets due to their lack of shedding and small size)[/small]
uncle_rico_thumb.jpg
 
What constitutes as a word boundary? I'm guessing start and end of string would be immediate inclusions. Empty space characters (space, tab, newline) fit in that category as well? And what about special characters (!@#$^ etc.)?

-kaht

Looking for a puppy? [small](Silky Terriers are hypoallergenic dogs that make great indoor pets due to their lack of shedding and small size)[/small]
uncle_rico_thumb.jpg
 
Sorry, I wasn't expecting such a quick reply, although I don't understand what's happened in either of those one liners they both worked a treat, Thanks guys.
 
I see, thanks for the explanation! Have another star on me [smile]

-kaht

Looking for a puppy? [small](Silky Terriers are hypoallergenic dogs that make great indoor pets due to their lack of shedding and small size)[/small]
uncle_rico_thumb.jpg
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top