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

Thank you for your quick and very good answer , that really helped me .

but I have got some new question , hope you help me please :

I want to change this string to new string whether there is '@' or not. For example two of them should replace to that :
string file = "this is a sample text";

or
string file = @"this is a sample text";

to
string file = Function(@"this is a sample text");

also if there is a Function() method , should not be used again :
string file = Function(@"this is a sample text");

to
string file = Function(@"this is a sample text");

I know this is really hard to find , but I am not able to find that , wish someone help me .
Posted
Updated 10-Dec-09 4:33am
v4

1 solution

Sorry if the below doesn't show up. Code Project seems to have a bug. Something in the below code is preventing it from showing up when I click the "Preview" tab. Oh well, let's just hope is a preview problem and that this actually does show up once the answer is posted:

// This goes at the top of your file.
using System.Text.RegularExpressions;

// This code does what you want.
string pattern = @"(?<RESULT>\"".*?\"")";
string replace = "Function(${RESULT})";
string input = @"string file = ""this is a sample text"";";
string result = Regex.Replace(input, pattern, replace);
MessageBox.Show(result);
 
Share this answer
 

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