0
if (cmd == "card_request") {

   Debug.Log("FOund cards");
   ISFSObject responseParams = (SFSObject)evt.Params["params"];
   Debug.Log(responseParams.GetClass("cards").ToString());
   SFSArray data = (SFSArray)responseParams.GetSFSArray("cards");
   Debug.Log(data.GetUtfString(0));

   //for (int i = 0; i < data.GetUtfString(0).IndexOf("value"); i++) {
     firstSplit = data.GetUtfString(0).Split(';');
     Debug.Log(firstSplit);
   //}
   for (int i = 0; i < firstSplit[0].IndexOf("value"); i++) {
     secondSplit = firstSplit[0].Split(':');
     Debug.Log(secondSplit);
   }
   for (int i = 0; i < secondSplit[0].IndexOf("value"); i++) {
     thirdSplit = secondSplit[0].Split(',');
     Debug.Log(thirdSplit);
   }
}

the data is coming fine at this line Debug.Log(data.GetUtfString(0)); But when I try to split it it gives errors. Somebody can please suggest me the effective way to split UTF string. Null exceptions occurs at secondSplit and thirdSplit

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
allrounder
  • 49
  • 6
  • What errors do you get? – DavidG May 26 '14 at 08:00
  • I also try this foreach (string s in data.GetUtfString(0)) { firstSplit = s.Split(';'); Debug.Log(firstSplit); } but then it says can not convert type char to string – allrounder May 26 '14 at 08:04
  • @DavidG: No any error in the above code, but firstSplit getting nothing it is empty, that's why null exceptions occurred at second and third split. – allrounder May 26 '14 at 08:08
  • my problem is that why utf string is not splitting, is there any other method to split the utf strings. – allrounder May 26 '14 at 08:19
  • `Spilt` will only return null if the result of `data.GetUtfString(0)` is also null. – DavidG May 26 '14 at 08:39
  • @DavidG: data.GetUtfString(0) is not null, as it have the value Naja:15,25,36,7,9 I want to split those values, to get numbers 15,25,36,7,9. But it always resturns firstSplit empty. – allrounder May 26 '14 at 08:58
  • Debug.Log(data.GetUtfString(0)); here it shows the value Naja:15,25,36,7,9 – allrounder May 26 '14 at 08:59
  • Are you sure that calling `GetUtfString` can be done multiple times? – DavidG May 26 '14 at 09:02
  • In my opinion calling GetUtfString multiple times must not cause any issue. But I am not pretty sure. – allrounder May 26 '14 at 09:04
  • So what do you get if you call it twice, like this? `Debug.Log(data.GetUtfString(0)); Debug.Log(data.GetUtfString(0));` – DavidG May 26 '14 at 09:07
  • I get the same output twice. Naja:30,15,6,7,9 Naja:30,15,6,7,9 – allrounder May 26 '14 at 09:10
  • But when I do Debug.Log(data.GetUtfString(0).Split(',')) it returns empty. – allrounder May 26 '14 at 09:31
  • If your log is : System.String[], it doesn't mean its empty, it is a type. – Verv May 26 '14 at 09:38
  • Yes my log is System.String[] and i resolved the problem now by using firstSplit = data.GetUtfString(0).Split(';'); Debug.Log(firstSplit[0]); foreach(string keyValPair in firstSplit) { string[] tokens = keyValPair.Split(':'); Debug.Log(tokens[0]); foreach(string cardNum in tokens[1].Split(',')) { Debug.Log(cardNum); } } Now I can see the result value. – allrounder May 26 '14 at 09:47

0 Answers0