How can you separate a String in java without using a delimiter

0

From a String 2654993672 , what I want is to separate it into two parts.

String part1 = "26";
String part2 = "54993672";

With the split () method I can separate them with a delimiter ...

String[] parts = string.split("-");
String part1 = parts[0]; 
String part2 = parts[1];

But what I need is to separate them without using it.

    
asked by Adolfi Téllez 04.12.2018 в 20:09
source

1 answer

0

To divide the string without using delimiter you can use 'substring' It has a simple use:

var str = "Hello world!";
var res = str.substring(1, 4); -> res == "ell"

Understanding what are the arrangements that always start with the 0 position, you should think that str at the moment of dividing is an array of chars and substring (POSITIONAL, POSFINAL) takes two positions of the array.

First POSITIONAL is the position N > = 0 where you want your string to start, and POSFINAL the last position NO INCLUSIVE

To see the example better, go to this link

    
answered by 04.12.2018 в 20:58