literals

in CoffeeScript, how can I use a variable as a key in a hash?

℡╲_俬逩灬. 提交于 2019-11-30 21:22:42
问题 eg: So: foo = "asdf" {foo: "bar"} eval foo # how do I get {"asdf": "bar"} ? # this will throw parse error: {(eval foo): "bar"} This is a simple syntax question: how do I get CoffeeScript to construct a hash dynamically, rather than doing it by hand? 回答1: For anyone that finds this question in the future, as of CoffeeScript 1.9.1 interpolated object literal keys are supported! The syntax looks like this: myObject = a: 1 "#{ 1 + 2 }": 3 See https://github.com/jashkenas/coffeescript/commit

Unicode (hexadecimal) character literals in MySQL

做~自己de王妃 提交于 2019-11-30 20:26:36
Is there a way to specify Unicode character literals in MySQL? I want to replace a Unicode character with an Ascii character, something like the following: Update MyTbl Set MyFld = Replace(MyFld, "ẏ", "y") But I'm using even more obscure characters which are not available in most fonts, so I want to be able to use Unicode character literals, something like Update MyTbl Set MyFld = Replace(MyFld, "\u1e8f", "y") This SQL statement is being invoked from a PHP script - the first form is not only unreadable, but it doesn't actually work! You can specify hexadecimal literals (or even binary literals

Why is it possible to assign a const char* to a char*?

别来无恙 提交于 2019-11-30 17:26:30
I know that for example "hello" is of type const char* . So my questions are: How can we assign a literal string like "hello" to a non- const char* like this: char* s = "hello"; // "hello" is type of const char* and s is char* // and we know that conversion from const char* to // char* is invalid Is a literal string like "hello" , which will take memory in all my program, or it's just like temporary variable that will get destroyed when the statement ends? Konrad Rudolph In fact, "hello" is of type char const[6] . But the gist of the question is still right – why does C++ allow us to assign a

Convert UTF-8 to string literals in Python

最后都变了- 提交于 2019-11-30 14:18:54
I have a string in UTF-8 format but not so sure how to convert this string to it's corresponding character literal. For example I have the string: My string is: 'Entre\xc3\xa9' Example one: This code: u'Entre\xc3\xa9'.encode('latin-1').decode('utf-8') returns the result: u'Entre\xe9' If I then continue by printing this: print u'Entre\xe9' I get the result: Entreé This is great and close to what I need. The problem is, I can't make 'Entre\xc3\xa9' a variable and pass it through the steps as this now breaks. Any tips for getting this working? Example: a = 'Entre\xc3\xa9' b = 'u'+ a.encode('latin

What's wrong with JavaScript's regular expression notation?

人盡茶涼 提交于 2019-11-30 14:06:31
问题 I was reading Douglas Crockford's web page, JavaScript: The World's Most Misunderstood Programming Language, and I couldn't help but notice that, under Design Errors, he mentions "the notation for literal regular expressions." What exactly is he talking about? What's wrong with JavaScript's notation for regular expressions, and why? 回答1: Might have to do with the fact that it enforces you to escape / characters, perhaps he wanted a more unique character to use as the notation. /test// is

PHP object literal

允我心安 提交于 2019-11-30 11:43:13
问题 In PHP, I can specify array literals quite easily: array( array("name" => "John", "hobby" => "hiking"), array("name" => "Jane", "hobby" => "dancing"), ... ) But what if I want array of objects? How can I specify object literal in PHP? I.e. in javascript it would be: [ {name: "John", hobby: "hiking"}, {name: "Jane", hobby: "dancing"} ] 回答1: As BoltClock mentioned there is no object literal in PHP however you can do this by simply type casting the arrays to objects: $testArray = array( (object

C# verbatim string literal not working. Very Strange backslash always double

∥☆過路亽.° 提交于 2019-11-30 09:31:20
问题 I've tried for quite a long time to figure out whats going on but I've not found anything anywhere that someone besides me has ran into this issue. I'm simply trying to hard code a path into a string. Easy stuff. Well for some reason string fullPathSourceFile = @"c:\SQLSOURCE.txt"; is evaluating to c:\\SQLSOURCE.txt I've tried everything to evaluated it to a single backslash remove the double quotes and it wont work. I even tried Replace(@"\\", @"\") and it has no affect. Anyone have any idea

Assigning an integer literal to a double variable in Java

倾然丶 夕夏残阳落幕 提交于 2019-11-30 09:01:10
问题 If I do the following double d = 0; since 0 is an integer literal, which uses 32 bits, and d is a double variable that uses 64 bits, will the remaining 32 bits be filled with random garbage, or does Java promote the literal correctly? 回答1: Java promotes it correctly, otherwise there'd be a rather large body of code that was problematic :-) Section 5.1.2 of the Java language spec details this: The following 19 specific conversions on primitive types are called the widening primitive

MySQL unicode literals

对着背影说爱祢 提交于 2019-11-30 08:32:05
I want to insert a record into MySQL that has a non-ASCII Unicode character, but I'm on a terminal that doesn't let me easily type non-ASCII characters. How do I escape a Unicode literal in MySQL's SQL syntax? dkamins See: http://bugs.mysql.com/bug.php?id=10199 (Bug #10199: "Allow Unicode escape sequence for string literals.") This request has been "Open" since 2005. More details in Worklog Task #3529: Unicode Escape Sequences . From https://web.archive.org/web/20091117221116/http://eng.kaching.com/2009/10/mysql-unicode-escape-sequences.html though, you can see the following example, which

Is 0 an octal or a decimal in C? [duplicate]

和自甴很熟 提交于 2019-11-30 07:43:47
问题 This question already has answers here : Is 0 a decimal literal or an octal literal? (3 answers) Closed 5 years ago . I have read this. It's octal in C++ and decimal in Java. But no description about C? Is it going to make any difference if 0 is octal or decimal? This is the question asked by my interviewer. I said no and I explained that it is always 0 regardless whether it is octal or decimal. Then he asked why is it considered as octal in C++ and decimal in Java. I said it's the standard.