Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to split a string while ignoring the case of the delimiter?

Tags:

string

c#

.net

I need to split a string let's say "asdf aA asdfget aa uoiu AA" split using "aa" ignoring the case. to

"asdf " "asdfget " "uoiu " 
like image 534
jdelator Avatar asked Sep 16 '09 23:09

jdelator


People also ask

How do you split a string without delimiter?

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.

What does split return if delimiter not found?

split (separator, limit) , if the separator is not in the string, it returns a one-element array with the original string in it.

How do you split a string into parts based on a delimiter?

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.


1 Answers

There's no easy way to accomplish this using string.Split. (Well, except for specifying all the permutations of the split string for each char lower/upper case in an array - not very elegant I think you'll agree.)

However, Regex.Split should do the job quite nicely.

Example:

var parts = Regex.Split(input, "aa", RegexOptions.IgnoreCase); 
like image 181
Noldorin Avatar answered Sep 21 '22 17:09

Noldorin