LINQ Group By and not contains usage issue

i like to eliminate those user data which start with VM & Voice Mail

var csvlines = File.ReadAllLines(@"M:\smdr(backup08-06-2015).csv"); var csvLinesData = csvlines.Skip(1).Select(l => l.Split(',').ToArray()); var groupOfUser = from line in csvLinesData where !line[12].contains('VM') and !line[12].contains('Voice Mail') group line by line[12] into newGroup orderby newGroup.Key select newGroup;

this line where !line[12].contains('VM') and !line[12].contains('Voice Mail') giving error and error is Too many characters in character literal


It's not SQL but C#, so a string has quotes not apostrophes and it's && not and, change it to:

where !line[12].Contains("VM") && !line[12].Contains("Voice Mail")

The '' should be used to define character literal like a single digit or alfa. To define string you should use "":

where !line[12].Contains("VM") && !line[12].Contains("Voice Mail")

Too many characters in character literal

A character literal is denoted using single quotes and should be a single character - ie 'VM' and 'Voice Mail' are too long for a character literal. In C#, you have to use double quotes for strings. In addition, you need to use &&, not and:

where !line[12].contains("VM") && !line[12].contains("Voice Mail")

Category:c# Time:2018-12-21 Views:5
Tags: linq

Related post

  • LINQ Group By and NOT in 2011-03-29

    I have a schema like below (it's a simplified example so please ignore the obvious schema issues): table Books { string bookId } table students_books { string studentname string bookId } The intent is to find out books read less than 500 times. Unfor

  • Cannot login after the OneNote update - WS-Federation response does not contain an issued token 2012-05-09

    Hi, I am having trouble logging in to my office 365 subscription after the latest OneNote update. The same problem also happens using the OneNote/OneDrive iOS apps after the latest update. We use single sign on via okta. After providing my credential

  • CSS selector that ends with something and not contains something 2011-11-08

    I need to find any <a> tags, which its href ends with 'pdf' and not contains 'test'. like this; <a href="/abc/tes.pdf">link</a> All I know is the first condition; jQuery('a[href$=".pdf"]') Teach me the rest. Thank you. -------------

  • How can I once and for all verify my account so that I can send group emails and not have to jump through the "to prevent spam verify your account hurdle"? 2012-08-05

    It seems like every time I go to send a group email -- even to just five or six people -- I am asked to pass an anti-spam verification test. I then also follow the instructions to verify my account for good -- but I keep getting asked to verify on su

  • Orphaned Class Module and 'Not enough memory' issue 2011-01-19

    A database that I have been working on appears to have run aground unfortunately I cant seem to get it back on track and it appears to be corrupted some what. I removed 2 forms, but it appears that there class modules are still there when you access

  • alert when url is exact url and not containing other parameters 2011-03-03

    I've got two urls: I want to alert when the url is and not if (location.href == "") { alert ('hel

  • self-join and group by giving "not contained in aggregate function" (SQL-server) 2011-04-19

    Good day, Here's what I'm trying to do.. ITEM | CATEGORY | AMOUNT Sponge A 29 Sponge B 32 Sponge C 33 Sponge D 34 Rod A 1 Rod B 2 Rod C 3 Rod D 4 And I wanted the output to look like this: ITEM | A | B | C | D Sponge 29 32 33 34 Rod 1 2 3 5 I've been

  • NHIbernate (3.1) - Linq group by then order by count issue 2011-05-17

    I am trying to get a group by followed by an order by count to work but I keep getting a 'Antlr.Runtime.NoViableAltException' being thrown. Here is the simplest error case I can create. var results = ArticleStatsRepository.GetAll().GroupBy(x => x.

  • Linq group by and order by multiple conditions 2012-01-16

    I have the following: myFilteredContractors = (From c In myFilteredContractors Join cc In myConClasses On c.ContractorId Equals cc.ContractorId Where inClassifications.Contains(cc.ClassificationId) Group c By Key = cc.ContractorId Into Group, Count =

  • EF4 - Linq to SQLite and List.Contains strange behaviour 2012-01-24

    I have some issue querying my local sqlite-database. Below is the current code: public static Dictionary<Guid, string> GetHashedComanyMembers(List<Guid> IdsToSearch) { using (var dbContext = new DbEntities(GetConnectionString())) { var te

  • Linq to Entities and LEFT OUTER JOIN issue with MANY:1 relations 2010-03-22

    Can somebody tell me, why does Linq to Entities translate many to 1 relationships to left outer join instead of inner join? Because there's referential constraint on DB itself that ensures there's a record in the right table, so inner join should be

  • LINQ grouping by and creating a formula based on the returned results 2010-03-22

    I need some help adding conditions to a linq query. Take this small example static void Main(string[] args) { List<ItemEntry> items = new List<ItemEntry>(); items.Add(new ItemEntry(1,1,5,1)); items.Add(new ItemEntry(2, 1, 5, 1)); items.Ad

  • How to download a large file with the iPhone SDK and avoid memory usage issues? 2009-03-08

    I'm using the NSURLConnection class to download a large file in my iPhone application, but it crashes every so often because it's using too much memory. I'm doing the usual NSURLConnection usage, to append the received data to a NSMutableData object.

  • LINQ to Objects - Does Not Contain? 2009-06-11

    I have a collection of Items that each have a collection of Relationships. I have a list of Groups that Items can have Relationships with. I can find all the Items that have a particular relationship but I now want to find all the Items that don't ha

  • Linq group by and count - how do I add more columns? 2009-12-22

    I have the following linq query from c in AllContracts group c.StatusId by c.StatusDescription into g select new {StatusDescription = g.Key, CountOf = g.Count()} which returns StatusDescription CountOf End date has passed 1 Suspended 1 Setup phase 2

  • LINQ group by and combine as CSV 2011-02-24

    This is what I have ID Value 1 Val1 1 Val2 3 Val3 3 Val4 4 Val5 I need ID Value 1 Val1, Val2 3 Val3, Val4 5 Val4 I am stuck at this point: var groups = Result.GroupBy(res => res.ID); foreach (var group in groups) { foreach (var entry in group) { }

  • Linq grouping by Max not working 2011-12-22

    I have a table with products Id | Name | Order 1 | product 1 | 5 1 | product 1 | 9 1 | product 1 | 2 2 | product 2 | 0 3 | product 3 | 1 I need to return just the product with the max order number: Id | Name | Order 1 | product 1 | 9 2 | product 2 |

  • SQL: How do you select only groups that do not contain a certain value? 2012-02-20

    Say I have a table: Restaurant locations: RESTAURANT_NO | RESTAURANT_LOCATION ----------------------------------- 1 | City A 1 | City B 2 | City A 2 | City B 2 | City C 3 | City C 4 | City A 4 | City B How would I be able to group them together and a

  • LINQ: Grouping By and Selecting from a List of objects based on max value 2012-02-29

    I have the MyItem class with 3 properties as below: class MyItem { private string _name; private int _value private DateTime _TimeStamp; public MyItem(string name, int value, string timeStamp) { this._name = name; this._value = value; this._timeStamp

  • Search only returns with words starting with a string and not containing a string. 2014-08-18

    I had Outlook 2010 installed and recently upgraded to Exchange 2010. After upgrade of account, the search function now only returns search results with words that being with the search string. Before it would contain all items that contained the sear

Copyright (C), All Rights Reserved.

processed in 0.574 (s). 13 q(s)