help convert char to string

Hi
You can help me is possible convert char to string?
tenks

what do you mean by “chat”?

1 Like

exuseme char

convert char to string

What do you mean by ‘convert char to string’? Can you give an example?

1 Like

Do this:

 ""+your char

Adding “” to a number, does the trick… so, i guess adding “” to your char will do it.

2 Likes
public var test : char;
function Start ()
{
	Debug.Log (test + "something ?");
}

An empty line in the console.

Edit : the inverse is not true.

public var test : char;
function Start ()
{
	Debug.Log ("something ?" + test);
}

This returns “something?” in the console…

I read a value from the database in char format but I want to convert char in string to insert in a label

As mentioned above, you can add a char to an empty string - the char will get “promoted” to string to enable the conversion.

I haven’t found a way to assign any value to a godda** variable of type char…what does it want exactly ?

It wants Single Quotes.

string myString = “This”;
char myChar = ‘T’;

This means you can also use escape sequences.

char newLine = ‘\n’;

public var test : char = 'T';

Works fine in C# :frowning:

Sadly as well, it looks like there is no implicit conversion from anything to char in .NET as well.
You could at best find the binary or hex value and cast.

It looks like the single quotes was not implemented in UnityScript.

var myChar = “T”[0];

Use System.Convert.ToChar.

–Eric

To convert a char[ ] to string in js is:
var c : char[ ] = new char[5000000];
sr.Read(c, 0, c.Length);
var s:String = new String(c);
var fileContents : String = “”+c;
sr.Close();

What? Are you asking a question or giving a “solution”?

To convert a Char to a String:
string stringFromChar = addedChar.ToString();

To convert a String to Char:
char charFromString = addedString.ToCharArray()[0];

Replace 0 with the index of the string you wish to turn to char.