Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you pull apart a string?

Tags:

java

string

I'm storing a string in a database with a value such as "020734". I would like to be able to pull the string apart.

I have:

String values = "020734";

I need:

String values = "020734";
String value1 = "02";
String value2 = "07";
String value3 = "34";

Could you guys possibly point me in a general direction?

like image 261
Brian Avatar asked Dec 22 '22 23:12

Brian


2 Answers

Erm, how about value1 = values.substring(0, 2); value2 = values.substring(2,4)...etc? That will get you two characters at a time from the string.

like image 130
Tikhon Jelvis Avatar answered Jan 06 '23 10:01

Tikhon Jelvis


checkout String.substring.

String values = "020734";
String value1 = values.substring(0, 2);
String value2 = values.substring(2, 4);
String value3 = values.substring(4, 6);
like image 42
krock Avatar answered Jan 06 '23 09:01

krock