Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to split into character group? [duplicate]

I want to split string

"abcdefgh"

to

"ab","cd","ef","gh"

using javascript split()

"abcdefgh".split(???)

Can you please help ?

like image 276
Prashant Bhate Avatar asked Apr 14 '11 20:04

Prashant Bhate


People also ask

How do you split a string into characters?

To split a string with specific character as delimiter in Java, call split() method on the string object, and pass the specific character as argument to the split() method. The method returns a String Array with the splits as elements in the array.

Can a string be split on multiple characters?

Method 1: Split multiple characters from string using re. split() This is the most efficient and commonly used method to split multiple characters at once. It makes use of regex(regular expressions) in order to do this.

How do you split the same character in Python?

Python split() method is used to split the string into chunks, and it accepts one argument called separator. A separator can be any character or a symbol. If no separators are defined, then it will split the given string and whitespace will be used by default.

How do you split a character in VB net?

How to VB.NET String. Split() The VB.Net Split() extracts the substrings from the given string that are delimited by the separator parameter, and returns those substrings as elements of an array. If your String contains "dd-mm-yy", split on the "-" character to get an array of: "dd" "mm" "yy".


Video Answer


1 Answers

Instead of split, try match:

var text = "abcdefgh";
print(text.match(/../g));

prints:

ab,cd,ef,gh

as you can see on Ideone.

like image 183
Bart Kiers Avatar answered Nov 09 '22 08:11

Bart Kiers