String

  • Thread starter Thread starter shapper
  • Start date Start date
S

shapper

Hello,

I have the following string:

MyString = "Posted by $Author$ @ $DateTime${HH:mm}"

I want to create two strings out of the one before:

a = "Posted by $Author$ @ $DateTime$" ... everything outside {}

and

b = "HH:mm" ... everything inside {}

How can I do this?

Thanks,

Miguel
 
shapper said:
Hello,

I have the following string:

MyString = "Posted by $Author$ @ $DateTime${HH:mm}"

I want to create two strings out of the one before:

a = "Posted by $Author$ @ $DateTime$" ... everything outside {}

and

b = "HH:mm" ... everything inside {}

How can I do this?

Thanks,

Miguel

You can use the RegEx.Matches method with a pattern like "^(.+){(.+)}$"
to match the two strings that you mention.

If I would guess what you are trying to do, you actally want to match
"$Author$" and "$DateTime${HH:mm}" and replace them. That can be done
with the RegEx.Replace method with a pattern like
"\$(.+?)\$(?:{(.+?)})?" and a delegate that returns the string to
replace them depending on the match.
 
Back
Top