How to split string between different chars
You can use String.Split()
method with params char[]
;
Returns a string array that contains the substrings in this instance that are delimited by elements of a specified Unicode character array.
string text = "the dog :is very# cute";
string str = text.Split(':', '#')[1]; // [1] means it selects second part of your what you split parts of your string. (Zero based)
Console.WriteLine(str);
Here is a DEMO
.
You can use it any number of you want.
use this code
var varable = text.Split(':', '#')[1];
That's not really a split at all, so using Split
would create a bunch of strings that you don't want to use. Simply get the index of the characters, and use SubString
:
int startIndex = text.IndexOf(':');
int endIndex = test.IndexOf('#', startIndex);
string very = text.SubString(startIndex, endIndex - startIndex - 1);