Browsing 7239 questions and answers with Jon Skeet

Remove brackets dots and white spaces from string

I am using asp.net mvc c#.This is my string string filename = "excluder version(1). final" I want to concatinate string with result filename = "excluderversion1final" How to...
Jon Skeet
people
quotationmark

Sounds like a good candidate for Regex.Replace: private static readonly Regex RemovalRegex = new Regex(@"\s|[().]"); ... public static string RemoveUnwantedCharacters(string input) { return RemovalRegex.Replace(input, ""); } Note... more 8/27/2015 10:34:19 AM

people

ASCII Code Of Characters

In C# I need to get the ASCII code of some characters. So I convert the char To byte Or int, then print the result. String sample="A"; int AsciiInt = sample[0]; byte AsciiByte =...
Jon Skeet
people
quotationmark

But For Characters Upper Than 128 I get Irrelevant answers No you don't. You get the bottom 8 bits of the UTF-16 code unit corresponding to the char. Now if your text were all ASCII, that would be fine - because ASCII only goes up to... more 8/27/2015 5:50:12 AM

people

What JVM checks in Java object equality (==)?

what does JVM checks in object equality (==)? Is it the hashCode of two objects or something else ?
Jon Skeet
people
quotationmark

The == operator only checks reference equality. It doesn't call any methods on the object... it just checks whether the two references involved are equal, i.e. they refer to the same object. In simple cases I believe this is just a matter... more 8/27/2015 5:47:10 AM

people

IndexOutOfBounds error inserting into sorted list

Could someone tell me why i keep getting an IndexOutOfBoundsException? Cheeses are just an array containing a set of strings. Alphabets is a class containing a single string...
Jon Skeet
people
quotationmark

Look at this loop: while ((alphabets.getAlp().equalsIgnoreCase(arrayList.get(i).substring(0, 1))) && (i < count)) { str.add(arrayList.get(i)); i++; } Note how you call arrayList.get(i) before you check for i <... more 8/26/2015 5:42:43 PM

people

Sending Protocol Buffered object in .Net ApiController to protobuf.js

I am trying to use Proto-buf c# library in .net. I am using an ApiController and the System.Net.WebSockets namespace. It has a way of getting an incoming...
Jon Skeet
people
quotationmark

If you just need a Stream to deserialize from, you can use: var stream = new MemoryStream(buffer.Array, buffer.Offset, result.Count); ArraySegment<byte> is already wrapping a byte[], so you just need to create a MemoryStream... more 8/26/2015 4:33:03 PM

people

Visual Studio 2015 missing new keyword no compiler error

I was working on one of our new applications when I made a stupid mistake… I forgot to write: ”new ClassName” inside an object initializer. Strangely VS just compiled the code…...
Jon Skeet
people
quotationmark

There's nothing wrong there at all. It's using an object initializer for End which sets properties using the existing value instead of assigning a new value to End. Your code is equivalent to: var tmp0 = new MyClass(); var tmp1 = new... more 8/26/2015 2:52:17 PM

people

returning specified type for a linq query with anonymous type

i have this query: DbQuery<Logs> logs = context.GetQuery<Logs>(); var MessageLogs = logs.Where( s => s.DATE == date.Date .GroupBy(s...
Jon Skeet
people
quotationmark

Given that your current query returns elements with key/date/count, it sounds like you probably just want: var result = query.GroupBy( x => x.Key, (key, rows) => new Data { Key = key, Val = rows.Select(r =>... more 8/26/2015 12:24:33 PM

people

Select * From tab1, tb2, tb3, etc in LINQ

I am trying to convert the above statement to LINQ. I have multiple tables (with an identifier in the first column) and I need to "multiply" them so that I get a table as a result...
Jon Skeet
people
quotationmark

In a LINQ query expression you just need multiple from clauses, e.g. var query = from row1 in tab1 from row2 in tab2 from row3 in tab3 select new { row1, row2, row3 }; If you don't want to use query... more 8/26/2015 12:02:57 PM

people

Download zipball from github in C#

Need to download a zipball from given link in C# YES! I searched the net and stackoverflow and been trying to accomplish this seemingly impossible task for hours... Ironically,...
Jon Skeet
people
quotationmark

When I tried this with WebClient, I didn't get a 403, but an exception: System.Net.WebException: The server committed a protocol violation. Section=ResponseStatusLine Looking up other questions with the same error, I found that the... more 8/26/2015 10:19:33 AM

people

C# NUnit unit test not using correct method return to compare

I have the following class public static class MyClass { public static double Converter(int mpg) { return Math.Round((double)mpg / ((double)36 / 12.74), 2); ...
Jon Skeet
people
quotationmark

The unit test shows the same result as I see when executing the code. Here's a short but complete program to show the exact result retrieved, using my DoubleConverter class. using System; class Test { static void Main() { ... more 8/26/2015 9:29:44 AM

people