tostring

Converting an object to a string

笑着哭i 提交于 2019-11-26 01:25:46
问题 How can I convert a JavaScript object into a string? Example: var o = {a:1, b:2} console.log(o) console.log(\'Item: \' + o) Output: Object { a=1, b=2} // very nice readable output :) Item: [object Object] // no idea what\'s inside :( 回答1: I would recommend using JSON.stringify, which converts the set of the variables in the object to a JSON string. Most modern browsers support this method natively, but for those that don't, you can include a JS version: var obj = { name: 'myObj' }; JSON

How to get the entire document HTML as a string?

空扰寡人 提交于 2019-11-26 00:36:03
问题 Is there a way in JS to get the entire HTML within the html tags, as a string? document.documentElement.?? 回答1: MS added the outerHTML and innerHTML properties some time ago. According to MDN, outerHTML is supported in Firefox 11, Chrome 0.2, Internet Explorer 4.0, Opera 7, Safari 1.3, Android, Firefox Mobile 11, IE Mobile, Opera Mobile, and Safari Mobile. outerHTML is in the DOM Parsing and Serialization specification. See quirksmode for browser compatibility for what will work for you. All

Enum ToString with user friendly strings

梦想与她 提交于 2019-11-26 00:16:18
问题 My enum consists of the following values: private enum PublishStatusses{ NotCompleted, Completed, Error }; I want to be able to output these values in a user friendly way though. I don\'t need to be able to go from string to value again. 回答1: I use the Description attribute from the System.ComponentModel namespace. Simply decorate the enum: private enum PublishStatusValue { [Description("Not Completed")] NotCompleted, Completed, Error }; Then use this code to retrieve it: public static string

Why does the toString method in java not seem to work for an array

妖精的绣舞 提交于 2019-11-25 23:38:09
问题 I want to convert a character array to a string object using the toString() method in java. Here is a snippet of the test code I used: import java.util.Arrays; class toString{ public static void main(String[] args){ char[] Array = {\'a\', \'b\', \'c\', \'d\', \'e\', \'f\'}; System.out.println(Array.toString()); } } In principle, it should print abcdef , but it is printing random gibberish of the likes of [C@6e1408 or [C@e53108 each time the program executes. I don\'t need an alternative out

Problem with converting int to string in Linq to entities

痴心易碎 提交于 2019-11-25 22:47:23
问题 var items = from c in contacts select new ListItem { Value = c.ContactId, //Cannot implicitly convert type \'int\' (ContactId) to \'string\' (Value). Text = c.Name }; var items = from c in contacts select new ListItem { Value = c.ContactId.ToString(), //Throws exception: ToString is not supported in linq to entities. Text = c.Name }; Is there anyway I can achieve this? Note, that in VB.NET there is no problem use the first snippet it works just great, VB is flexible, im unable to get used to

to_string is not a member of std, says g++ (mingw)

♀尐吖头ヾ 提交于 2019-11-25 22:41:26
问题 I am making a small vocabulary remembering program where words would would be flashed at me randomly for meanings. I want to use standard C++ library as Bjarne Stroustroup tells us, but I have encountered a seemingly strange problem right out of the gate. I want to change a long integer into std::string so as to be able to store it in a file. I have employed to_string() for the same. The problem is, when I compile it with g++ (version 4.7.0 as mentioned in its --‍version flag), it says: PS C:

How to convert decimal to hexadecimal in JavaScript

落花浮王杯 提交于 2019-11-25 22:23:41
问题 How do you convert decimal values to their hexadecimal equivalent in JavaScript? 回答1: Convert a number to a hexadecimal string with: hexString = yourNumber.toString(16); And reverse the process with: yourNumber = parseInt(hexString, 16); 回答2: If you need to handle things like bit fields or 32-bit colors, then you need to deal with signed numbers. The JavaScript function toString(16) will return a negative hexadecimal number which is usually not what you want. This function does some crazy

How do I print my Java object without getting “SomeType@2f92e0f4”?

点点圈 提交于 2019-11-25 22:09:47
问题 I have a class defined as follows: public class Person { private String name; // constructor and getter/setter omitted } I tried to print an instance of my class: System.out.println(myPerson); but I got the following output: com.foo.Person@2f92e0f4 . A similar thing happened when I tried to print an array of Person objects: Person[] people = //... System.out.println(people); I got the output: [Lcom.foo.Person;@28a418fc What does this output mean? How do I change this output so it contains the