Click here to Skip to main content
15,919,434 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Friends..

i have a string "select Code from table where columnname= nvl(#p_name,columnname)"
here i need to replace #p_name as null.
Expecting output shoulb be like "select Code from table where columnname= nvl(null,columnname)"
it is possible to get that output using Regx.Replace
Posted
Updated 16-Aug-13 0:27am
v2
Comments
[no name] 16-Aug-13 6:29am    
"it is possible to get that output using Regx.Replace", yes. Yes it is possible.
SPASWIN 16-Aug-13 6:32am    
Sir.
i tried to construct Regx like @"^#.,$"
its not working bcoz its wrong.Could you pls help me to do this
Thomas Daniels 16-Aug-13 6:34am    
Do you want to replace all #[here something] or do you just want to replace #p_name with null?
SPASWIN 16-Aug-13 6:38am    
yes Sir i need to replace #p_name with null...
but i shldnt hardcode p_name anywhere
Ashutosh Mahto 16-Aug-13 6:40am    
#p_name is a constant part of string or there can be a pattern like this? If #p_name is a constant part that you want to replace then you can simply do like -
string str = select Code from table where columnname= nvl(#p_name,columnname)";
str = str.Replace("#p_name","null");

1 solution

Yes, it's possible, try this:
C#
string original = "select Code from table where columnname= nvl(#p_name,columnname)";
string result = Regex.Replace(original, "#(.+)( *),", "null,");

Hope this helps.
 
Share this answer
 
v3
Comments
SPASWIN 16-Aug-13 6:37am    
Thank you Sir.
here i should't hardcode p_name because p_name will change dynamically.
Is there anyother way to achive this..
Thomas Daniels 16-Aug-13 6:39am    
Yes, there's another way, I updated my answer.
SPASWIN 16-Aug-13 6:40am    
Thank you Sir.
Thomas Daniels 16-Aug-13 6:41am    
You're welcome!

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