Question by
ShahanButt · Oct 29, 2015 at 11:35 AM ·
unity5stringvar
problem in var atemp : String[]
using UnityEngine; using System.Collections;
public class textdisplay1 : DestrroyOnClick { public TextAsset asset;
public int searchWord (string a) {
var aTemp : String[] = tWordList.text.Split("\n"[0]);
return 1;
}
}
Comment
Answer by Landern · Oct 29, 2015 at 12:49 PM
You're mixing Javascript and c#, if you want to split a string based off new line, give it a couple options for different platforms to split on, i.e. \n and \r\n
I assume the variable tWordList is derived from DestrroyOnClick or somewhere down the chain as there isn't a direct reference in the textdisplay1 class.
using UnityEngine; using System.Collections;
public class textdisplay1 : DestrroyOnClick {
public TextAsset asset;
public int searchWord (string a) {
string[] aTemp = tWordList.text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
// display string array items in Unity Console for sanity check.
if (aTemp != null){
for (int i = 0; i < aTemp.Length; i++) {
Debug.Log("WordList Word: " + aTemp[i]);
}
}
return 1;
}
}