aparenlty strings cannot be strings :( CS0029: Cannot implicitly convert type `string[]' to `string'

Ive looked this up but google fu only finds int to string act,
I’v come across: CS0029: Cannot implicitly convert type string[]' to string’
so a string cannot be a tring don’t get it…

using UnityEngine.UI;
public class LoginRegister : MonoBehaviour {

	public string UserLoginURL = "http://earthaalianceonline.com/loggin";
	public string UserRegiesterURL = "http://earthaalianceonline.com/register";
	public string Username = "";
	public string Password = "";
	public bool Login = false;

	public Text XPText;
	public Image XPbar;
	public Text GoldText;
	public Text LevelText;
	public Text UsernameText;

	public GameObject Logedin;


	//------------------------------------------------------------------------------------

	void OnGUI()
	{
		Username = GUILayout.TextField (Username);
		Password = GUILayout.TextField (Password);
		if (GUILayout.Button ("Log in")) {
			StartCoroutine(LoginUser());

		}
	}

	//------------------------------------------------------------------------------------

	IEnumerator LoginUser(string User, string Pass ) {
		WWW Login = new WWW (UserLoginURL + "Username" + User + "Password" + Pass);
		yield return Login;
		if (Login.error == null) {
			// display resaults:		???
			UsernameText.text = Login.text.Split(","[0]);
			GoldText.text = Login.text.Split(","[1]);
			XPText.text = Login.text.Split(","[2]);
			LevelText.text = Login.text.Split(","[3]);
			}
		}
	}
	//---------------------------------------------------------------------------------

Well, string is not the same as string :wink:

string is a string. A collection of characters.

string is a string array. A collection of strings.

string.Split returns a collection of strings rather then a single string. (splitted on whatever you provide as argument).

You are getting the right idea by using the [0] etc. behind it, but you placed that at the wrong place. Because string is actually a collection of characters. This line:

GoldText.text = Login.text.Split(","[1]);

actually says split login on the second character of this string: “,”. (Split allows you to provide a character instead of a string as argument so this is valid according to the compiler) Now it is true that “,” only has one character and this would actually create a indexoutofrange exception r something similar if it were to compile in the first place :wink:

What you want to do is this instead:

GoldText.text = Login.text.Split(",")[1];

Which says, split on “,” and then result number one.

You obviously have to do that for every string.Split in there.