473,804 Members | 1,971 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

filter string over regular expression

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




Nov 19 '05 #1
4 1780
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.

"Xavier" <Xa****@discuss ions.microsoft. com> wrote in message
news:76******** *************** ***********@mic rosoft.com...
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



Nov 19 '05 #2
i tryed to use the match with the folowing function

vInputString = Regex.Replace(v InputString, "^--.*\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

"Kevin Spencer" wrote:
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.

"Xavier" <Xa****@discuss ions.microsoft. com> wrote in message
news:76******** *************** ***********@mic rosoft.com...
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




Nov 19 '05 #3
> 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.

"Xavier" <Xa****@discuss ions.microsoft. com> wrote in message
news:D2******** *************** ***********@mic rosoft.com...i tryed to use the match with the folowing function

vInputString = Regex.Replace(v InputString, "^--.*\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

"Kevin Spencer" wrote:
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.

"Xavier" <Xa****@discuss ions.microsoft. com> wrote in message
news:76******** *************** ***********@mic rosoft.com...
> 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
>
>
>
>
>
>
>
>
>
>


Nov 19 '05 #4
yes, i also noticed this...
Now it's all fine

thanks, for your help
Xavier
"Kevin Spencer" wrote:
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.

"Xavier" <Xa****@discuss ions.microsoft. com> wrote in message
news:D2******** *************** ***********@mic rosoft.com...
i tryed to use the match with the folowing function

vInputString = Regex.Replace(v InputString, "^--.*\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

"Kevin Spencer" wrote:
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.

"Xavier" <Xa****@discuss ions.microsoft. com> wrote in message
news:76******** *************** ***********@mic rosoft.com...
> 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
>
>
>
>
>
>
>
>
>
>


Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
39359
by: Anand Pillai | last post by:
To search a word in a group of words, say a paragraph or a web page, would a string search or a regexp search be faster? The string search would of course be, if str.find(substr) != -1: domything() And the regexp search assuming no case restriction would be,
3
11879
by: Edwin G. Castro | last post by:
Hi, I'm new to XSLT and I'm having a hard time figuring out whether XSLT will do what I need it to do. I have a XML file with a whole bunch of <message> elements. These <message> elements have <!]> in them. I would like to use XSLT to remove the <message> elements whose CDATA (the "...") matches a particular regular expression.
32
14917
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if ((someString.IndexOf("something1",0) >= 0) || ((someString.IndexOf("something2",0) >= 0) ||
29
4328
by: zoro | last post by:
Hi, I am new to C#, coming from Delphi. In Delphi, I am using a 3rd party string handling library that includes some very useful string functions, in particular I'm interested in BEFORE (return substring before a pattern), AFTER (return substring after a pattern), and BETWEEN (return substring between 2 patterns). My questions are: 1. Can any tell me how I can implement such functionality in C#? 2. Is it possible to add/include function...
0
1899
by: Anonieko Ramos | last post by:
Answer. Use IHttpHandler. thanks Ro ry for coming up with this code. It processes css file to add variables. neat idea using System; using System.IO; using System.Text; using System.Text.RegularExpressions; using System.Web; using System.Web.Caching;
7
2664
by: Brian Mitchell | last post by:
Is there an easy way to pull a date/time stamp from a string? The DateTime stamp is located in different parts of each string and the DateTime stamp could be in different formats (mm/dd/yy or dd/mm/yyyy, or hh:mm:ss dd/mm...etc.) Any ideas would be appreciated, Thanks!!
20
3722
by: Opettaja | last post by:
I am new to c# and I am currently trying to make a program to retrieve Battlefield 2 game stats from the gamespy servers. I have got it so I can retrieve the data but I do not know how to cut up the data to assign each value to its own variable. So right now I am just saving the data to a txt file and when I look in the text file all the data is there. Not sure if this matters but when I open the text file in Word pad (Rich Text) It...
11
303
by: xyz | last post by:
I have a string 16:23:18.659343 131.188.37.230.22 131.188.37.59.1398 tcp 168 for example lets say for the above string 16:23:18.659343 -- time 131.188.37.230 -- srcaddress 22 --srcport 131.188.37.59 --destaddress 1398 --destport tcp --protocol
6
15946
by: Zetten | last post by:
I have an AD search module which works as I want it to; searching for a matching forename and/or surname in the appropriate OU. I would like to extend it to be more flexible, so that instead of just searching for a matching string in the surname/forename fields it can match partial strings. I already have it applying a star to the end of the filter, which accomplishes part of this, but I would like it to match partial strings at the start as...
0
9593
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10595
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10343
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7633
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5529
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5668
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3831
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.