I receive a WebService
string similar to this: 19 Y 19-A
(they are street crossings).
what I need is that I can keep the values 19
and 19-A
, eliminating the "Y" from the string , so that they remain in 2 strings, something like this:
String1=19
String2=19-A
It has to be considered that, in some records, the letter "y" can exist as the name of one of the two crosses, that is what is creating this dilemma for me. I attach the code that I have so far (logically I changed the string to help exemplify:
String string = "19 Y 19-A";
String[] parts = string.split("Y");
String part1 = parts[0]; // 19
String part2 = parts[1]; // 19-A
I always prefer the use of REGEX, but another valid option is to define the separator as " Y " (since you comment: "in some records, the letter "y" can exist as the name of one of the two crossings"), in this way you would get the required values.
Test:
Explanation of the regular expression: