Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android equivalent to PHP's function explode()

Pretty much self-explanatory.

I have a string:

8:4,7:2,...

I need to get the values from this, the length of the string is not defined, it just has this format:

id:quantity,id:quantity,...
like image 806
Mike Bryant Avatar asked Feb 02 '12 13:02

Mike Bryant


People also ask

What does the explode () function do?

The explode() function breaks a string into an array. Note: The "separator" parameter cannot be an empty string.

What does the explode () function return?

The explode() function splits a string based on a string delimiter, i.e. it splits the string wherever the delimiter character occurs. This functions returns an array containing the strings formed by splitting the original string.

How do you use implode and explode in JavaScript?

Answer: Use the JavaScript split() method If you want to explode or split a string from a certain character or separator you can use the JavaScript split() method. The following example will show you how to split a string at each blank space. The returned value will be an array, containing the splitted values.

What is explode in programming?

A built-in function in PHP that splits a string into different strings is known as explode(). The splitting of the string is based on a string delimiter, that is, explode in PHP function splits the string wherever the delimiter element occurs.


2 Answers

use string's split method to get this:

String[] array = "8:4,7:2".split(",");
like image 158
waqaslam Avatar answered Oct 14 '22 11:10

waqaslam


if you want to split string to array use split function

String string="8:4,7:2";
String[] array_from_string = string.split(",");

if you want to join array elements to string use join function

String string_from_array = String.join(",", array_from_string);
like image 26
Naham Soft Avatar answered Oct 14 '22 09:10

Naham Soft