I have a string like:
"super exemple of string key : text I want to keep - end of my string"
I want to just keep the string which is between "key : "
and " - "
. How can I do that? Must I use a Regex or can I do it in another way?
I have a string like:
"super exemple of string key : text I want to keep - end of my string"
I want to just keep the string which is between "key : "
and " - "
. How can I do that? Must I use a Regex or can I do it in another way?
You already have some good answers and I realize the code I am providing is far from the most efficient and clean. However, I thought it might be useful for educational purposes. We can use pre-built classes and libraries all day long. But without understanding the inner-workings, we are simply mimicking and repeating and will never learn anything. This code works and is more basic or "virgin" than some of the others:
You end up with your desired string assigned to the parsedString variable. Keep in mind that it will also capture proceeding and preceding spaces. Remember that a string is simply an array of characters that can be manipulated like other arrays with indices etc.
Take care.
A working LINQ solution:
You can do it without regex
You can use the extension method below:
Usage is:
or, with a regex.
with a running example.
You can decide if its overkill.
or
as an under validated extension method