How would you convert object[,]
to string[,]
?
Object[,] myObjects= // sth
string[,] myString = // ?!? Array.ConvertAll(myObjects, s => (string)s) // this doesn't work
Any suggestions appreciated.
EDIT : Of course, a loop solution will obviously do it, however I was envisioning a more elegant solution both in terms of code and in performance.
EDIT2 : The object[,]
contains of course string
s (and digits, but this doesn't matter for now).
Stringify a JavaScript ObjectUse the JavaScript function JSON.stringify() to convert it into a string. const myJSON = JSON.stringify(obj); The result will be a string following the JSON notation.
Converting Object to String Everything is an object in Python. So all the built-in objects can be converted to strings using the str() and repr() methods.
toString() The toString() method returns a string representing the object.
We can also convert the string to an object using the Class. forName() method.
You can allocate space like this
string[,] myString = new string[myObjects.GetLength(0),myObjects.GetLength(1)];
Then some loops should work fine, like this:
for(int k=0;k < myObjects.GetLength(0);k++)
for(int l=0;l < myObjects.GetLength(1);l++)
myString[k,l] = myObjects[k,l].ToString();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With