i want to split the String = "Asaf_ER_Army" by the "ER" seperator. the Split function of String doesn't allow to split the string by more than one char.
how can i split a string by a 'more than one char' seperator?
Use the String. split() method to split a string with multiple separators, e.g. str. split(/[-_]+/) . The split method can be passed a regular expression containing multiple characters to split the string with multiple separators.
C allows users to store words and sentences with the help of the char data type. Character data type stores only a single character, but a person's name has more than one character. We can create an array of characters to store such data with more than one character 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.
Also, there is a multi-character literal that contains more than one c-char. A single c-char literal has type char and a multi-character literal is conditionally-supported, has type int, and has an implementation-defined value.
It does. Read here.
string source = "[stop]ONE[stop][stop]TWO[stop][stop][stop]THREE[stop][stop]";
string[] stringSeparators = new string[] {"[stop]"};
// Split a string delimited by another string and return all elements.
string[] result = source.Split(stringSeparators, StringSplitOptions.None);
Edit: Alternately, you can have some more complicated choices (RegEx). Here, http://dotnetperls.com/string-split.
String.Split
does do what you want. Use the overload that takes a string array.
Example:
string[] result = "Asaf_ER_Army".Split(
new string[] {"ER"},
StringSplitOptions.None);
Result:
Asaf_ _Army
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