filter string over regular expression

G

Guest

hello,

in a string which i read from a textfile there are some lines, which must be
eliminated.
The content of the stringvariable is for example :

myString="
--comment 1
Update .....
--comment 2 .......
SELECT DISTINCT .....
...."

how can i eliminate all the comment lines marked with --
so that i get

myString="
Update .....
SELECT DISTINCT .....
...."

The new string has no more lines with --

thanks
Xavier
 
K

Kevin Spencer

Hi Xavier,

The following will match any line that begins with "--"

(?m)^--.*\r*\n

You can use Regex.Replace to take them out.
--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.
 
G

Guest

i tryed to use the match with the folowing function

vInputString = Regex.Replace(vInputString, "^--.*\r*\n", "")

where the inputstring is the value what i get from the textfile and has the
value
vInputString ="
--comment 1
select * from Table1 where AreaId=1001
--other comment

--comment 2
Select * from table 2
--GO--
"

I want to eliminate all lines what beginns with --
The result must be in my example only
vInputString ="
select * from Table1 where AreaId=1001
Select * from table 2"



but i did not work

any idea?

thanks
 
K

Kevin Spencer

but i did not work

Apparently not.
any idea?

Try using the WHOLE Regular Expression I gave you:

(?m)^--.*\r*\n

The following is a link to a FREEWARE Regular Expression Building and
Testing tool that works quite well:

http://www.ultrapico.com/Expresso.htm

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top