I have a string User name (sales)
and I want to extract the text between the brackets, how would I do this?
I suspect sub-string but I can't work out how to read until the closing bracket, the length of text will vary.
I have a string User name (sales)
and I want to extract the text between the brackets, how would I do this?
I suspect sub-string but I can't work out how to read until the closing bracket, the length of text will vary.
If you wish to stay away from regular expressions, the simplest way I can think of is:
This code is faster than most solutions here (if not all), packed as String extension method, it does not support recursive nesting:
This one is little longer and slower, but it handles recursive nesting more nicely:
A very simple way to do it is by using regular expressions:
As a response to the (very funny) comment, here's the same Regex with some explanation:
Use a Regular Expression:
I'm finding that regular expressions are extremely useful but very difficult to write. So, I did some research and found this tool that makes writing them so easy.
Don't shy away from them because the syntax is difficult to figure out. They can be so powerful.
I came across this while I was looking for a solution to a very similar implementation.
Here is a snippet from my actual code. Starts substring from the first char (index 0).