Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
234 views
in Technique[技术] by (71.8m points)

asp.net - Get String with Specific Tags in C#

I'm looking for a way to get strings from a string with specific tags, e.g. I have this string: "Hello <date> My <name> is <your name>" I need to return this: <date> <name> <your name>

in an array or a list

only words starts and ends with <>.

Thanks a million! :-)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can use the Regex pattern <.*?> to retrieve each word, ie

MatchCollection matches = Regex.Matches(input, "<.*?>");

You can then iterate over the collection to get the tags.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...