String str = "\u0054\u0068\u0069\u006e\u006b\u0050\u0061\u0064"; String[] strArray = str.split("\\");
but this error occured.
Exception in thread "main" java.util.regex.PatternSyntaxException: Unexpected internal error near index 1
Java split() function is used to splitting the string into the string array based on the regular expression or the given delimiter. The resultant object is an array contains the split strings.
\\s - matches single whitespace character. \\s+ - matches sequence of one or more whitespace characters.
split is faster, but complex separators which might involve look ahead, Regex is only option.
The "split is not a function" error occurs when we call the split() method on a value that is not of type string. To solve the error, convert the value to a string by using the toString() method before you call split() , or make sure to only call the split method on strings. Here is an example of how the error occurs.
it should be
String[] strArray = str.split("\\\\");
the reason why is because in Regex
, \
has special meaning so you need to escape it into \\
.
and in java, \\
should be equal to "\\\\"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With