tostring

C# Double - ToString formatting to show a value in cents with no decimal displayed.

I have a situation where I need to display a double value rounded to two decimal places, but displayed without the decimal. There will be some situations where I will want to use the same code and display the double value differently, so I was hoping I could handle this by passing in a string format pattern. For example, the double val...

Which number <-> string conversions are always consistent, regardeless the localization settings?

I have some issues with number <-> string conversion i cannot sort out. We have written a serialization framework which uses several xml serialization techniques. But i have seen some inconsistent number conversions in the generated output: using: var c = TypeDescriptor.GetConverter(double); var s = c.ConvertToString(value); and va...

Can Javascript get a function as text?

Can Javascript get a function as text? I'm thinking like the inverse of eval(). function derp() { a(); b(); c(); } alert(derp.asString()); The result would be something like "a(); b(); c();" Does it exist? ...

.Net Throwing exceptions from ToString?

Just curious if anyone has any opinions on throwing an exception in my overridden ToString implementation. My instincts tell me this might be bad practice, but I don't seem to be able to find anything supporting if this is bad or not. Any thoughts? Code: http://pastebin.com/mLEkBAAz Thanks. ...

java: what is this: [Ljava.lang.Object; ?

I get this when I call toString on an object I received from a function call. I know the type of the object is encoded in this string, but I don't know how to read it. What is this type of encoding called? ...

AS3: Can ByteArray return its content as a string with two bytes per unicode character?

var bytes:ByteArray = new ByteArray; bytes.writeInt(0); trace(bytes.length); // prints 4 trace(bytes.toString().length); // prints 4 When I run the above code the output suggests that every character in the string returned by toString contains one byte from the ByteArray. This is of course great if you want to display the content of t...

Converting ArrayList of objects to ArrayList of this objects String names in Java

I have an ArrayList of User objects. Now I need the ArrayList of these user's names only. Is there a way to use toString() on entire ArrayList and convert it to ArrayList of String names rather than doing this in for loop? I have also overridden toString in User class so it returns user's name, and I have tried ArrayList <String> names =...

A template class in C++

What is the function of the following C++ template class? I'm after line by line annotations: template<class T> string toString(const T& t, bool *ok = NULL) { ostringstream stream; stream << t; if(ok != NULL) *ok = stream.fail() == false; return stream.str(); } Is it like Java's toString() method? ...

Android + toString

Hi Everybody! Can anybody please tell what toString in Android is for and how it can be used? As example would be highly appreciated. Thanks in Advance john ...

Provide Programmatic Access to All Data Available in String Form: toString()

Bloch said: Provide Programmatic Access to All Data Available in String Form. I am wondering if he means to override toString() which should involve 'all data available'? I think the 'in string form' means that the string is for human reading, so override toString() is enough for the advice. Am I correct? ...

How to I return different type with __toString() method?

We use __toString() to returning class's default value like that: <?php class my { public function __toString() { return "asdasd"; } } ?> It returns only string type. But I want to return resource type: <?php class my { public function __toString() { return imagecreatefromjpeg("image.jpg"); } } ?> ...

Why is myEnum.ONE not equal to myEnum.ONE.toString() ?

I've got the following enum: public enum myEnum { ONE("ONE"), TWO("TWO"); private String name; private myEnum(String name) { this.name = name; } @Override public String toString() { return name; } }; My question is why does the following evaluate to false? I suspect it has something to do...

Add an empty string vs toString - why is it bad?

According to the tool PMD, the following is a bad practice: String s = "" + 123; // bad String t = Integer.toString(456); // ok This is an inefficient way to convert any type to a `String`. Why is it a bad thing to do? ...

How to represent a .NET DateTime 24-hour format in 01-24 instead of 00-23?

I have a strange business requirement to output dates as 01:00 through 24:00, instead of the usual 00:00 through 23:00. It is really a crazy requirement, but unfortunately I don't think I can avoid it. This will be a configuration option in our software, so I'll still need to support the normal 00-23 as well, so I'm hoping I can do thi...

Most efficient Dictionary<K,V>.ToString() with formatting?

What's the most efficient way to convert a Dictionary to a formatted string. e.g.: My method: public string DictToString(Dictionary<string, string> items, string format){ format = String.IsNullOrEmpty(format) ? "{0}='{1}' " : format; string itemString = ""; foreach(var item in items){ itemString = itemString + St...

Javascript error Permission denied for <http://www.mydomain.com> to call method Location.toString on <http://clientdomain.com>.

Hi, We have prepared a Javascript based embeddable application. It works well on all the websites. But one website publisher is facing trouble when embed our application, there is a javascript error which I have mentioned in the title. Permission denied for http://www.mydomain.com to call method Location.toString on http://cl...

c# combobox overridden ToString

Hello guys, I am experiencing some problems while working with ComboBox. The display member for my combobox is not being populated by the overridden ToString method of class MAP. Here is my code: Form1.cs: private void Form1_Load(object sender, EventArgs e) { ... ... MAPList MAP = new MAPList(); comboBox1...

JavaScript: toString

How come Object.prototype.toString === toString? If I have this in the global scope: var toStringValue = toString.call("foobaz"); I would expect toStringValue to be the value of window.toString because window is the default scope, right? How come toString by itself resolves to Object.prototype.toString instead of window.toString? ...

What's a good toString method for a deftype'd object in clojure

(deftype Bag [state] Object (toString [bag] (str "Bag???" state))) I want the toString to look something like clojure.core=> (def b (Bag. {:apples 1 :bannanas 4})) #'clojure.core/b clojure.core=> (str b) "BAG: {:apples 1 :bannanas 4}" What is a nice clojurey way of representing that information? Is "Bag/{:k :v}" ...

Example where [DebuggerDisplay(...)] attribute is useful?

I am looking for a good concrete example where it is clearly desirable to override ToString() with something, but to use a [DebuggerDisplay(...)] custom attribute to display something else in the debugger? ...