Reputation: 49
I have this code which is written in c# however, I want to convert this code from c# to java, when I use split method in java it required a String parameter however in my case I have String[], so it cannot be applied, please tell me how to transfer these 2 line of codes, you assistance is highly appreciated.
string[] stringSeparators = new string[] { "3B3D3B" };
string[] separatedHex = returnHex.Split(stringSeparators,
StringSplitOptions.RemoveEmptyEntries);
Upvotes: 0
Views: 221
Reputation: 696
Looking at C# documentation it looks like Split(String[])
uses delimiter array as alternative delimiters.
As you have already noticed java does not have "split by array" method. But single string parameter in java is actually regular expression. Because of this you could join your your delimiters with alternative operator.
string[] stringSeparators = new string[] { "3B3D3B" };
string[] separatedHex = returnHex.split(String.join("|",stringSeparators));
But make sure your separator deos not contain any special regex characters - or make sure they are escaped with \
Upvotes: 2
Reputation: 2452
What about this code, let me know if this one works:
String stringSeparators = "3B3D3B";
String[] separatedHex = returnHex.split(stringSeparators);
Upvotes: 2