[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

how to check if first character is not a letter

Posted on 2009-12-27
6
Medium Priority
?
274 Views
Last Modified: 2013-11-11
I have the following linq select statement

var posts = from c in feed.Descendants("artist").Where(c => (c.Element("name").Value.Substring(0, 1)) == letter)

this works fine, but now i need a way to select everything else. How can i select "artist" who's first letter does not start with letter.
0
Comment
Question by:frosty1
  • 3
  • 2
6 Comments
 
LVL 7

Expert Comment

by:tipsybroom
ID: 26127377
var posts = from c in feed.Descendants("artist").Where(c => (c.Element("name").Value.Substring(0, 1)) != letter)
0
 

Author Comment

by:frosty1
ID: 26127384
sorry let explain further. I want to get all artist whose name doesn't begin with a letter. ie "123 My Band"

0
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 26127542
Hi frosty1;

The code snippet below will return the Element with the tag "name" that does NOT start with a letter.

Fernando
var posts = from c in feed.Descendants("artist")
            let firstChar = c.Element("name").Value.ToCharArray().First()
            where firstChar < 'A' | firstChar > 'z'
            select c ;

Open in new window

0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
LVL 64

Accepted Solution

by:
Fernando Soto earned 2000 total points
ID: 26127557
Sorry Re-post, I used a bit wise Or where I should have used a conditional Or.
var posts = from c in feed.Descendants("artist")
            let firstChar = c.Element("name").Value.ToCharArray().First()
            where firstChar < 'A' || firstChar > 'z'
            select c ;

Open in new window

0
 

Author Comment

by:frosty1
ID: 26127653
thanks FernandoSoto !! spot on :)
0
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 26127659
Not a problem, glad I was able to help.  ;=)
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Loops Section Overview
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month19 days, 1 hour left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question