Click here to Skip to main content
15,916,412 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
If the user inputs <get property = "name"> so I want it to be replaced with the value of key "name" present in properties dictionary.
VB
templete = Regex.Replace(templete, "<get property = ""(.*)"">", ?)

What can I write in place of ? in the above code so that the <get> tag will be replaced by the value of dictionary where key is the value of property attribute.

Example
1. If the tag is <get property = "name"> so it should be replaced with dictionary("name").
2. If the tag is <get property = "age"> so it should be replaced with dictionary("age").
Posted
Updated 22-Dec-15 7:35am
v2
Comments
Sergey Alexandrovich Kryukov 22-Dec-15 13:46pm    
I don't see what prevents you from doing exactly that. You need to parse your string. You can parse it into regular expression, key, and the rest. It's just some programming, nothing which you don't know.

What have you tried so far?

However, I don't think your idea is practical. I would suggest to design something better. Unfortunately, you did not explain your ultimate goals.

—SA

1 solution

Try:
VB
Public Shared ReplaceName As New Regex("<get property = ""(?<Name>.*)"">")
...
Dim result As String = ReplaceName.Replace("<get property = ""John Smith"">", "dictionary(""${Name}"")")
 
Share this answer
 
Comments
Irfan Project 22-Dec-15 15:23pm    
Thanks OriginalGriff for your solution.. But still there is one problem

I want to pass the <name> value to dictionary as you did using ${Name} to retrieve the value of <name>. But while using it as a key in dictionary I am getting KeyNotFoundException.

This is because it is direcly passing "${Name}" as String rather than "John Smith" to dictionary..

So is there any solution to pass "John Smith" to other function rather than "${Name}"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900