Please I have a string such as this RemoteAuthorizationTestScope|Start:En Attente Validation|:001|:01195|21/01/2015
I can extract the string from the | symbol using this code
var userInfo="RemoteAuthorizationTestScope|Start:En Attente Validation|:001|:01195|21/01/2015"
var entries=userInfo.Split('|');
however, there are also text such "Start:En Attente Validation" in the string that needs to be separated, how do I achieve this so that I can have the string separated in this manner.
RemoteAuthorizationTestScope
Start
En Attente Validation
001
01195
21/01/2015
You can use the split() method of String class from JDK to split a String based on a delimiter e.g. splitting a comma-separated String on a comma, breaking a pipe-delimited String on a pipe, or splitting a pipe-delimited String on a pipe.
Splitting a string using strtok() in C In C, the strtok() function is used to split a string into a series of tokens based on a particular delimiter. A token is a substring extracted from the original string.
Use the string split in Java method against the string that needs to be divided and provide the separator as an argument. In this Java split string by delimiter case, the separator is a comma (,) and the result of the Java split string by comma operation will give you an array split.
Q #4) How to split a string in Java without delimiter or How to split each character in Java? Answer: You just have to pass (“”) in the regEx section of the Java Split() method. This will split the entire String into individual characters.
You can specify multiple characters to split and also remove empty entries. Use the String.Split overload
like:
var entries = userInfo.Split(new []{'|', ':'}, StringSplitOptions.RemoveEmptyEntries);
That will give you
RemoteAuthorizationTestScope
Start
En Attente Validation
001
01195
21/01/2015
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