Using RegEx In LINQ?

May 1, 2011

I am using LINQ and RegEx to select a list of files that need to be zipped, based on information given by the user (includefiles and excludefiles) .

This code works great until there is an escape character in the path, such as C:Program Files(x86). At that point, no files are selected for zipping.

I'm very unfamiliar with LINQ and RegEx, but I think I need Regex.Escape("(") (plus any other characters). I just don't know how I should go about putting it into the code.

I can't find any examples that use LINQ and also include Regex.Escape.

Dim DI As New DirectoryInfo(sDirectory)
Dim FileList As IEnumerable = From F In DI.GetFiles("*.*", SearchOption.AllDirectories) _

[Code]....

View 1 Replies


ADVERTISEMENT

Concatenating A Variable With A Regex Group Match In Regex.replace?

Apr 5, 2012

I am having an issue where I am using regex.Replace to replace part of a string. The basic idea is that I want to capture the beginning of the string then replace the end of the string with a value from code. For an example pretend I have a string that says "Test Number " followed by number and I want to increment that number. I capture the "Test Number " but when I try to concatenate that capture with the new number it treats the capture ($1) as a literal and replaces the entire string with $1[new number].

[code]...

This will output "We are on Test Number 2", as expected. how I can use a variable in the replacement string portion of the Regex.Replace when including a captured group?

View 1 Replies

Regex: Take Text & Some Special Characters Between The Xml Tags Using Regex On C#.net?

Feb 23, 2012

I want to take the text and some special characters between the xml tags.. My input file contains:

[Code]...

now i want the Regex to take text and the special characters between the tags <line>,<inline>..

View 2 Replies

Increment Regex Match Using Regex.Replace

Jun 21, 2012

I'm creating a program in VB.NET to output multiple images. Some images will have the same file name. If there is multiple files with the same name I want to add "_1_" to the end of the file name. If the "_1_" file already exists I want to increment the 1 to be "_2_". If this file already exists I want to continue incrementing the number ultil it doesn't exist. So for example "filename", filename_1_", "filename_2_", etc. Here is the code that I have tried

[Code]...

View 1 Replies

Regex Builder That Actually BUILDS RegEx From A Highlight

Nov 17, 2011

I've been working straight since yesterday trying to get this to work. I'm a noob to RegEx and I've tested out about 5 different RegEx "builders" but each of them require you to navigate through the options to build the Regex...each of them has failed when I try to use them.Is there an application out there free/paid where you select the line you want to grab and the RegEx is auto generated from that highlight rather than having to try to build the line of code? [code]

View 1 Replies

.net - ActiveRecord Linq/NHibernate Linq Not Building Query Completely?

Jul 14, 2011

given this function:

Public Function Search(ByVal StartIndex As Integer, _
ByVal MaxResults As Integer, _
ByVal AccountNumber As String, _
ByVal LastName As String, _

[Code]....

instead of what I expected:

Select count(*) from remitline where lastname = "smith"

What am I doing wrong building up the where clause? I'm using Castle ActiveRecord 2.1

View 1 Replies

Performance Gain In LINQ Query Vs LINQ Stored Procedure?

Aug 6, 2009

if there is that much of a performance gain in running a LINQ stored procedure versus a LINQ query?

View 1 Replies

Linq To Entities. GetPropety(name).GetValue Not Recognised By Linq?

Apr 20, 2011

I have a listbox on my xaml form that I bound to a List(Of MyType) property. I populated this list like so:

Dim fields As List(Of CheckableFields) = New List(Of CheckableFields)
Using context As ITIPEntities = New ITIPEntities()
Try[code]....

Now I'm at the point where the user selects the fields they want included in a report and I need to iterate over the required fields. This is my linq query:

For Each checkedField In _requiredFields
If checkedField.IsChecked Then
If checkedField.FieldData IsNot Nothing AndAlso checkedField.FieldData.Trim IsNot String.Empty Then[code].....

View 1 Replies

How To Get Lamda In LINQ To Actually Filter For Dynamic Linq

Sep 10, 2009

Example-I have a person class

Public Class Person
Private _fname As String
Public Property Fname() As String

[Code]...

View 2 Replies

LINQ Query Using The Dynamic LINQ Library?

Mar 31, 2011

Forgive my ignorance on this.I have this LINQ Query:Dim ngBikersDataContext As New CarBikeWalkDataContext

bikersList = (From c In ngBikersDataContext.Reg_Bikers _
Order By c.L_Name _
Select New Bikers() With { _
.BikerID = c.BikerID, _
.F_Name = c.F_Name, _

[Code]...

with the error "Overload resolution failed because no accesible 'Select' accepts this number of arguments."
Over the "NEW" I get an error " ')'expected."

View 1 Replies

"System.ArgumentException: An Item With The Same Key Has Already Been Added." When Trying To Order An In-memory LINQ Query By A LINQ Association?

Jan 27, 2011

We are doing a query against an in-memory collection of LINQ data objects. The wrinkle is that we are ordering by a column in a related table whose records have not necessarily been loaded yet (deferred loading:)

Dim oPkgProducts = _
From b In oBillPkg.BillProducts _
Where b.Successful.GetValueOrDefault(Common.X_INDETERMINATE) = _

[code]....

View 1 Replies

.net - Linq Expressions With Linq To Entities?

Feb 28, 2012

The pattern I'm trying to avoid is checking if a string (normally a control's text value) is null/empty, and if it is, comparing it using Contains to a field in my data. Obviously the field isn't hard-coded into my extension, neither is the object type.What I've got works perfectly in Linq to Objects, but I get the generic run-time error "LINQ to Entities does not recognize the method 'System.String Invoke(GenericQueryHelper.Customer)' method, and this method cannot be translated into a store expression." when using an entity framework model.

Here's what I have:

<System.Runtime.CompilerServices.Extension()>
Public Function CompareAndFilter(Of T)(source As System.Linq.IQueryable(Of T), expressionField As System.Linq.Expressions.Expression(Of System.Func(Of T, String)), compareTo As String)

[code]....

I want my usage to look something like this:

Dim results = repository.Customers.CompareAndFilter(Function(c) c.FirstName, searchText)

I do need to get this running against a SQL database really, as it is filtering results, so I don't want to be doing that in memory.

View 2 Replies

C# - Convert Code LINQ To SQL In C # LINQ To SQL In .net?

Jun 27, 2012

How can I convert this code LINQ to SQL in C # LINQ to SQL in Vb.net

[Code]...

View 2 Replies

LINQ To SQL - Add In Row_Number To A LINQ To SQL Query?

Aug 31, 2011

How do I add ROW_NUMBER to a LINQ query or Entity? How can I convert this solution to VB.NET?

[Code]...

I'm having trouble porting that last line. I have been unable to locate a VB.NET example. I'm actually not looking for any paging functionality like the example provides, just good old-fashioned Row_Number(Order By X) row index.

View 1 Replies

Convert An Object System.Data.Linq.DataQuery To System.Linq.IQueryable?

Oct 21, 2009

How can I convert an object of type System.Data.Linq.DataQuery to System.Linq.IQueryable?I'm working with Visual Basic/Silverlight, and the source code of my query is as follows:

Public Function Get_Cli_Pag() As IQueryable(Of V_Cliente_Pagare)
Dim Qry = From P In Me.Context.Pagares Join C In Me.Context.Codigos On C.Codigo

[code]....

View 1 Replies

VS 2010 Upgrade From 2008 To 2010 - Now LINQ - IntelliSense Is Not Working For LINQ Stuff

Apr 20, 2010

I just upgraded a project from VB 2008 to VB 2010. Before, the project did not use LINQ. I have started implementing it. So, I have updated the target framework from 2.0 to 3.5, and added a reference to System.Core, and imported the namespace System.LINQ to the entire project and also imported System.Data.LINQ into the form I'm working with (because it was not available in the list for Imported Namespaces in the references tab).

It's not throwing any errors now, but my IntelliSense is not working for LINQ stuff.

For example... I write this:

[CODE]....................

Then, if I type S. on the next line, the IntelliSense doesn't grab what it should for S (Only get Equals, GetHashCode, GetType, ReferenceEquals, and ToString, instead of the options I should get like Count, First, FirstOrDefault, etc...). If I Type S.First. then its the same thing, no IntelliSense that lists the available fields for S, just the standard options (Equals, GetHashCode, GetType, ReferenceEquals, and ToString). I should be seeing my column names in my table when I type S.FirstOrDefault.

So any ideas what is going on? When I type the code, for example, MessageBox.Show(S.FirstOrDefault.FirstName), it works perfectly. But it doesn't change the casing of the text (so it would read s.firstordefault.firstname) and no intellisense while doing it. But no errors. BTW - Everything works perfectly when creating a NEW VS 2010 application, it's just my projects upgraded from Visual Basic 2008 that have this issue.

View 2 Replies

LINQ Query Is Enumerated - Turn On Some Kind Of Flag That Alerts Me Each Time A LINQ Query Is Enumerated?

Sep 22, 2009

I know that LINQ queries are deferred and only executed when the query is enumerated, but I'm having trouble figuring out exactly when that happens.Certainly in a For Each loop, the query would be enumerated.What's the rule of thumb to follow? I don't want to accidentally enumerate over my query twice if it's a huge result.

For example, does System.Linq.Enumerable.First enumerate over the whole query? I ask for performance reasons. I want to pass a LINQ result set to an ASP.NET MVC view, and I also want to pass the First element separately. Enumerating over the results twice would be painful.It would be great to turn on some kind of flag that alerts me each time a LINQ query is enumerated. That way I could catch scenarios when I accidentally enumerate twice.

View 3 Replies

Converting Linq To C# Linq?

Feb 22, 2012

I recently switched from VB to C# and have, for the most part, been able to make the transition without too much trouble. Currently I am working on converting a VB.Net program into C# and am having trouble with a couple of code blocks that include Linq.

This is one of the VB.Net lines of code that I am having trouble with:

I have tried to do the same thing in C# like this:

I am getting a compile error on the dt, which says Could not find an implementation of the query pattern for source type 'System.Data.DataTable'.'GroupBy' not found. VS also has issues with the whole into Emailers = group;

I have tried to get this right using examples from my search but have not been able to get it right.

View 2 Replies

C# - How To Use Regex

Mar 12, 2012

I am using UrlRewriter.NET for urlrewriting...how do i write the regular expression for

[URL]

in this format <rewrite url = "~/ViewProfile/([^/.]+)" to="~/ViewProfile.aspx?uid=$1" /> what should be the rewrite url for [URL]

EDIT: Rewrite code in web.config file

<configuration>
<configSections>
<section name="rewriter" requirePermission="false" type="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandle‌​r, Intelligencia.UrlRewriter" />

[code]....

View 1 Replies

How To 2 Regex As One

Sep 28, 2011

I got xml document I want to parse. Here is example:[code]I want to get list of those to textbox like item1:1 newline item2:2 newline item3:3So its just like name+id and same for next..But sofar I got only item1 newline item2 newline item3

View 6 Replies

Regex Does Not End With?

Apr 9, 2012

I've got an application which loads up some Excel files and imports them into a database.There are only certain of the sheets which I want, which are all timestamped and have either an am or pm on them. I put together a regex expression to look for that in the sheet name and skip it if it doesn't meet that criteria as:

View 6 Replies

Using Regex In Vb?

Jun 15, 2009

i would like to use the following regex in VB.net:(d+.d+)|(??????)

how would i do it? i actually need to edit a string to put it in the specified format

View 2 Replies

.net - Getting The Regex Expression?

Apr 8, 2011

i have a string similar to this one:

Hi, <<
ame>> <<surname>>, this is an example << est>>.

I what a regex that match and split this string in:

"Hi, "
<<
ame>>
" "

[code]....

I tried this one: (<<*.*?>>)|(>>*.*?<<), but doesn't work.

View 2 Replies

.net Regex Get Information?

May 31, 2010

Well I am currently trying to get the word/text in between these 2 things

[Code]...

View 1 Replies

C# - Regex To Get The Tags?

Jan 14, 2011

I have a html like this :

<h1> Headhing </h>
<font name="arial">some text</font></br>
some other text
In C#,

I want to get the out put as below. Simply content inside the font start tag and end tag

<font name="arial">some text</font>

View 3 Replies

Converting Regex From .NET To C#?

Dec 24, 2011

I hired a coder to code me something in Regex. The issue was that he coded it in Visual Basic and I need it in C#. I tried using a converter but it didnt fix the issue.

string iamtwit = ss("http://www.mailinator.com" + GetBetween(GetBetween(iamtwit1, matches.ToString(), "</a>"), "<a href=", ">"));MessageBox.Show(GetBetween(matches1.ToString(), "<a href="", Strings.Chr(34)));

Here is the original code:

Dim iamtwit As String = ss("http://www.mailinator.com" & GetBetween(GetBetween(iamtwit1, matches.ToString, "</a>"), "<a href=", ">"))

MsgBox(GetBetween(matches1.ToString, "<a href=""", Chr(34)))

The error messages I am getting are:

The name 'GetBetween' does not exist in the current context

The name 'Strings' does not exist in the current context

View 3 Replies

Getting Regex To Work?

Sep 11, 2010

I'm currently trying to get a regular expression to work and I can't seem to get it to, I've used the regex that I am using on an online tester and the text that I'm searching for is being selected alright, but I don't appear to be able to get it to work in VB.Net, so I was wondering if anyone would be willing to give me a hand.

The code I have is;
Private Sub getLink(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs)

[code].....

View 3 Replies

How To Implement A Regex

Aug 12, 2011

I would like to use regex for a txt file as follows. What I want to do is to get the whole text if CRC is other than 00000000. The content of the file below has 2 blocks of data below. And I should get the second one after the regex operation.

[Code]...

View 3 Replies

REGEX Isn't Picking Up Everything It Should?

Apr 9, 2011

I'm using REGEX to scan the following two bits of javascript and get the stream url in the javascript codes below the regex.

REGEX:

Dim matchs As MatchCollection = New Regex("(window.SC.bufferTracks.push(){1}[^)^;]*();){1}").Matches(input)
Dim match As Match
For Each match In matchs[code].....

why it's working on one javascript, but not the other? (i've tested it on several, and it works on some and not on the others

View 4 Replies

RegEx To Get A String Between?

Aug 11, 2010

How can i get the String Between this I tried everything but I just cant make it:

This is the String:

Quote:

<a title="I Need this String" href="/page/view_7894135/I_Need_This_String.html" class="tinylink">I Need this String</a>

This was my RegEx but it doesent work. I tried everything:

(?<=title="">).+(?="")

View 5 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved