- Home /
issues splitting strings
I have a script that gets a long string from a database, i need to split it but i keep getting an error that says i cant convert a string to a char.
here is some sample data that it will need to split, i want to split at the "|" charactor : |1:130015:121|1:200013:121|1:140014:121|1:140011:121|1:140010:121|1:170012:121|1:170022:121|1:170007:121|1:110018:121|6:200012:110|1:130007:121|1:180020:121|1:200014:112|1:180016:211|1:170015:121|1:130014:011|1:160017:121|1:140007:121|1:150013:121|1:140015:112|1:140114:121|1:200114:121|1:190013:211|1:170013:121|6:160016:011|1:220007:121|6:180115:121|1:200115:112|6:190113:121|1:200017:121|6:170107:121|6:130017:121|6:150014:112|1:180015:110|6:160022:011|1:180013:211|6:160018:112|6:140018:121|6:130013:110|6:160008:121|6:130113:110|6:110017:110|6:180021:112|6:130010:121|6:170113:121|6:170108:121|6:180116:121|6:150011:211|1:170008:121|6:170112:121|1:130114:011|6:220018:121|1:170016:112|
private void GetVehicleDataFromString(string _data) { string[] _parts = _data.Split("|"); foreach (string _part in _parts) { Debug.Log(_part); } }
Answer by DaDonik · Jan 05, 2019 at 11:21 AM
Your problem is that anything within " is regarded to be a string. You need ' for that.
So _data.Split("|"); should be _data.Split('|');