Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert object[,] to string[,]?

Tags:

c#

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 strings (and digits, but this doesn't matter for now).

like image 482
HeinrichStack Avatar asked Apr 30 '13 10:04

HeinrichStack


People also ask

How do you convert an object to a string?

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.

How do I convert an object to a string in Python?

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.

Which of these function is used to convert object to string?

toString() The toString() method returns a string representing the object.

How do you convert a string object to a class object?

We can also convert the string to an object using the Class. forName() method.


1 Answers

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();
like image 90
Hogan Avatar answered Sep 30 '22 02:09

Hogan