Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to obtain substrings those are within the angular brackets in a string

Tags:

string

c#

.net

i think this would be really silly question , but iam not succesful with extratic srtings those within the angular barkets in a sentence .

var str = "MR. {Name} of {Department} department stood first in {Subjectname}"

i need to obtain the substrings (as array) those are within the angular brakets

like strArray should contain {Name,Department,Subjectname} from the above given string

like image 302
ravikiran Avatar asked Oct 14 '09 06:10

ravikiran


1 Answers

Noting the use of var in your question, I will assume that you are using .NET 3.5.
The one line of code below should do the trick.

string[] result = Regex.Matches(str, @"\{([^\}]*)\}").Cast<Match>().Select(o => o.Value).ToArray();
like image 65
Binoj Antony Avatar answered Sep 29 '22 09:09

Binoj Antony