Questions tagged [object-to-string]

"Object to string" is the concept of canonically representing an Object as a String.

64 questions
42
votes
3 answers

Python3 Error: TypeError: Can't convert 'bytes' object to str implicitly

I am working on exercise 41 in learnpythonthehardway and keep getting the error: Traceback (most recent call last): File ".\url.py", line 72, in question, answer = convert(snippet, phrase) File ".\url.py", line 50, in convert …
thewooster
  • 705
  • 1
  • 6
  • 19
14
votes
7 answers

Why my overriding method of toString() has to be public?

I am new to Java and I am learning the basics. I was studying the toString method and how to override it in my own classes. I am just wondering why has toString to be public? is it because it is defined so in the Object class?
mikey
  • 1,179
  • 5
  • 18
  • 38
10
votes
1 answer

Haskell's "deriving Show" in F#?

In Haskell it is easy to make an algebraic type/discriminated union "displayable" as a string by simply adding deriving Show to the type definition. In F# I end up writing things like: type Pos = | Pos of int * int override this.ToString()…
Miron Brezuleanu
  • 2,824
  • 2
  • 19
  • 31
10
votes
2 answers

value of integral type expected switch with dynamic parameter

Just out of curiosity. If I have the following Code public static string Format(dynamic exception) { switch (exception.GetType().ToString()) { case "test": return "Test2"; } return null; } i get the error "A…
6
votes
5 answers

How does Object.toString() work for different underlying types?

I don't understand why this works in java: If I have an Integer object in a object, example: Object myIntObj = new Integer(5); Now if i do: System.out.println(myIntObj); the output is: 5 I now that the Integer class has an ovveride of the toString…
Giovanni Far
  • 1,493
  • 5
  • 21
  • 36
6
votes
4 answers

How does the .ToString() method work?

Sometimes when I call a class's .ToString() method, it returns the fully qualified name of the class. But for some class's/struct's (like Int32) it returns a string correspoding to the object (value of the integer). Does this mean the Int32 class…
deen
  • 359
  • 1
  • 3
  • 10
5
votes
1 answer

Failed to override toString method

I wrote a timer class. And I want to override its toString method. But when I call the toString method, it still returns the super implementation. (fully qualified name of the class) Here is my timer class: import android.os.Handler; import…
Sweeper
  • 145,870
  • 17
  • 129
  • 225
4
votes
3 answers

PHP Assigning a default Function to a class

Im relatively new to PHP but have realized it is a powerfull tool. So excuse my ignorance here. I want to create a set of objects with default functions. So rather than calling a function in the class we can just output the class/object variable and…
IEnumerable
  • 3,230
  • 11
  • 42
  • 72
3
votes
3 answers

Mootools Element to HTML

My question is quite simple.. I need to convert an Element object into an html string var thumb = new Element('img',{'src':"big.jpg"}); console.log( thumb.?????() ); //some magical method here should return (as a string) '
pleasedontbelong
  • 18,077
  • 12
  • 47
  • 75
2
votes
3 answers

Construct a new Object() with the toString result of another Object

I was wondering if it was possible to get some String value of an Object to access that Object on the same machine (same RAM) or the same VM via that particular String. e.g. Object objA1 = new Object(); System.out.print(objA1.adress); => output:…
sinekonata
  • 345
  • 3
  • 11
2
votes
4 answers

how to convert pc serial number to string

First of all I'd like to know if I can use these two instructions gwmi win32_bios | select serialnumber gwmi win32_Computersystemproduct | select identifyingnumber indifferently. The second question is why if I write $sn = gwmi win32_bios | select…
Nicola Cossu
  • 49,868
  • 15
  • 89
  • 95
2
votes
1 answer

Tostring() method of custom powershell objects and export-clixml

1. I have these XML-files which contain data from 3rd-Party cmdlets exported via export-clixml as a backup.    They look like this (only with more objects):
Rob
  • 442
  • 4
  • 16
2
votes
1 answer

casting number to IFormattable not working as expected

I'm having trouble with casting a number to IFormattable, calling ToString(...) on it, and passing a FormatCode of the from 0.000;-;0 meaning that I want to display three decimal places of precision if the number is positive, display a "-" if…
Jake Smith
  • 1,742
  • 1
  • 21
  • 55
2
votes
1 answer

EditText.getText().toString() shows error

I want user to print his birthday to the edittext field. Then show this information in logs, but my app brake down and I don't know why :) Can you help me? start_set.xml-----
SergaRUS
  • 451
  • 7
  • 20
2
votes
2 answers

Is +"" better than .toString()?

Since myObject.toString() fails when myObject is null (throws a NullPointerException), it is safer to do myObject+"", since it's essentially doing String.valueOf(myObject).concat(""), which doesn't fail, but would instead result in the String…
Ben Leggiero
  • 25,904
  • 38
  • 161
  • 267
1
2 3 4 5