Linq on My.Resources (text file)

In VB.Net (VS 2013), I've added a text file as a resource to my project.

In LinqPad, I can query this file and get the desired result:

dim pre = (From line In File.ReadAllLines("F:\zUsers\Kap\Documents\Visual Studio 2013\Projects\LCT\MemberTicketEntry\ValidPrefixes.txt")
where line = "LCT").singleordefault
debug.print (pre)

Open in new window


If the file contains "LCT" as a line, it gets stored in pre.

But, in Visual Studio, when I substitute the hard coded text file with a resource (with Build set as Content), I get no results:

Dim pre As String = (From line In File.ReadAllLines(My.Resources.ValidPrefixes) _
						Where line = prefix).SingleOrDefault

						Debug.Print(".")

Open in new window


I don't get an error, but the Debug.print line never runs, even if I set a break point.

So, my question is:

How can I query a text file that's in my project resources?

PS: I can always just use the hard coded path (with application path), but it seems cleaner to include it as a resource -- for one reason, it would auto update with OneClick installs (I think).
KapriceAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ArkCommented:
Dim pre As String = (From line In My.Resources.ValidPrefixes.Split(vbNewLine) _
						Where line = prefix).SingleOrDefault

Open in new window

KapriceAuthor Commented:
That didnt' work. Breaking on the following line and examining the statement, ValidPrefixes does show the lines of the resources, but pre is set to Nothing.
KapriceAuthor Commented:
This also doesn't work:

Dim aPrefixes = My.Resources.ValidPrefixes.Split(vbNewLine)
		Dim pre As String = (From line In aPrefixes _
		Where line = prefix).SingleOrDefault

Open in new window


aPrefixes does show the prefix entries. But, pre still is Nothing.
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

ArkCommented:
probably there are spaces or some other invisible chars?
Try:
Where line.Contains(prefix)
KapriceAuthor Commented:
I don't know why, but this works, whereas the above, did not (I didn't try contains, though):

Dim prefixes As String()
Dim delimiter As Char() = vbNewLine
prefixes = My.Resources.ValidPrefixes.Split(delimiter)
Dim pre As String = (From p In prefixes Where p = prefix).SingleOrDefault()

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ArkCommented:
Oops, sorry, it's my fault ;)
Default split constructor accepts Char, not String. vbNewLine usualy is chr(13)+chr(10), thus Split actually use Chr(13) as a delimiter while chr(10) remain in parts.
You can also use overload split with strings:
My.Resources.ValidPrefixes.Split(New String() {vbNewLine}, StringSplitOptions.RemoveEmptyEntries)

Open in new window

PS. In your example u'r using another overload - an array of chars, where Dim delimeter as Char() splits vbNewLine into 2 chars (chr(13) & chr(10). If you look on prefixes in debugger you can see empty entries. You can add StringSplitOptions.RemoveEmptyEntries to your code as well.
KapriceAuthor Commented:
I awarded this as multiple solutions since the Expert led me in the right direction, but I came up with the solution.

Thanks so much for the help!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.