How to split a sentence into two separate arrays

String input0 = "G1 and G2 are the founders of Microsoft.";
String input1 = "The swimming medals were won by G1 and G2";

I would like to analyze the given lines and create 2 separate arrays (Note: G1, G2, G3, ... are placeholders for user input and would like to receive them separately)

e.g. for input0 the following arrays should be created array0 [G1, G2] and array1 [" and ", " is the founder of Microsoft."]
e.g for input1 the following arrays should be created array0 [G1, G2] and array1 ["The swimming medals were won by ", " and "]

I tried using the indexOffunctions and split, but so far I could not get it to work properly.

+3
source share
2 answers

. split. . , , , G1 G2 . , - : .split("G1|G2"), G1 G2 . indexOf . , ArrayList, indexOf G1 G2, , . .split .

+4

split ,

[] result = input0.split( "G [0-9]" );

G1, G2, G3 indexOf()

+1

Source: https://habr.com/ru/post/1781603/


All Articles