Browsing 7239 questions and answers with Jon Skeet

Little help using XmlTextWriter on writing "xhtml:link" element of sitemap.xml

Hello I'm trying to write a string like : <xhtml:link rel="alternate" hreflang="de" href="http://www.example.com/de" /> using XmlTextWriter class I've tried this piece...
Jon Skeet
people
quotationmark

You should change to use a different overload of XmlWriter.StartElement. For example: _writer.WriteStartElement("link", "http://www.w3.org/1999/xhtml"); That assumes you've already got a prefix alias of xhtml for the namespace... more 8/4/2014 12:34:46 PM

people

Why won't this variable load?

The Short Story I've created a program, below. I want to import a package I created into the program. I can't figure out why compiler doesn't recognize my address variable, whose...
Jon Skeet
people
quotationmark

Your address field within Address has no access modifiers - therefore it is only available to classes in the same package. Your EmployeeA class is not in the same package (it has no package statement), therefore it can't see it. You could... more 8/4/2014 12:21:41 PM

people

How to reduce same strings in a 'foreach'?

I'm new programming an have this issue that I couldn't get what i want to do, this is my code foreach(RunePage rune in runePages) { if(rune.Slots != null &&...
Jon Skeet
people
quotationmark

I would suggest using LINQ to group and count them: // TODO: Build up the whole string, and set the Text property once. // Oh, and rename richTextBox1 to something more descriptive. foreach (RunePage rune in runePages) { if... more 8/3/2014 7:06:17 PM

people

Decryption Works and Encryption Does not

I have converted an old project(crap, 0 documentation) from asp.net 1.1 to 4.5 ,which works fine.But now we have to change the connection strings of a project that interacts with...
Jon Skeet
people
quotationmark

This is problematic: return Encoding.ASCII.GetString(...); The result of encryption is arbitrary binary data. Do not try to convert it into a string like that - you'll almost always lose data. Instead, either just return the encrypted... more 8/2/2014 9:07:08 PM

people

Duration.parse example

I am using jodatime's Duration class: http://joda-time.sourceforge.net/apidocs/org/joda/time/Duration.html to add a duration like 02:10 to a DateTime like 2014-08-02T11:34 using...
Jon Skeet
people
quotationmark

The javadoc specifies the required format for Duration.parse: Parses a Duration from the specified string. This parses the format PTa.bS, as per AbstractDuration.toString(). You'll need to build a custom formatter - here's some... more 8/2/2014 7:35:09 PM

people

Why do these classes only compile when in the same file?

I have this directory c:\abcd it has no files in it, but has a subdirectory efgh. C:\abcd>dir Volume in drive C has no label. Volume Serial Number is B411-D580 Directory...
Jon Skeet
people
quotationmark

You're compiling without specifying a output "root" for the compiler to build up a package hierarchy from - so it just puts the class files in the same directory as the source files. Then it tries to find the classes later on, but it can't... more 8/2/2014 6:24:55 PM

people

Order list by Date with split between future as past dates

I am getting records from a database using Linq to Entities as follows: context.Orders.OrderBy(x => x.Schedule) In this case I am ordering by DateTime Schedule ... I would...
Jon Skeet
people
quotationmark

Right, it sounds like you want something like: DateTime startOfDay = DateTime.UtcNow.Date; var results = context.Orders .OrderBy(x => x.Schedule < startOfDay) .ThenBy(x =>... more 8/2/2014 2:45:05 PM

people

Compare string to 2 other strings

so i have this code part: private int checkErrors() { int error = 0; if (!(nether.Text.Equals("true"))) { error += 1; } if...
Jon Skeet
people
quotationmark

I suspect you're trying to find cases where it isn't "true" and it isn't "false". So something like: if (spawnMonster.Text != "true" && spawnMonster.Text != "false") { error++; } Alternatively, express the condition once,... more 8/2/2014 9:18:10 AM

people

Automatic crossing of function names by eclipse in the standard StdIn class

I copied and pasted a StdIn Class in eclipse which was used to complete an assignment in Stacks but suprisingly the names of functions readDoubles, readStrings and readInts were...
Jon Skeet
people
quotationmark

This is the key (example from readInts) * @deprecated For more consistency, use {@link #readAllInts()} The methods are deprecated, which means you should stop using them. more 8/2/2014 6:49:32 AM

people

How to replace ',)' with ')'

How to replace ',)' with ')' I gave replaceAll(",)",")") but i was getting an error that Unmatched closing ')' near index 0. Please let me know if there is some solution to...
Jon Skeet
people
quotationmark

replaceAll uses regular expressions, and bracket have a particular meaning in regular expressions. Just use replace instead, which doesn't use regex: text = text.replace(",)", ")"); more 8/1/2014 8:08:55 PM

people