Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How do you split strings into arrays with rows and columns?

Discussion in 'Scripting' started by D3Jason1, Mar 22, 2013.

  1. D3Jason1

    D3Jason1

    Joined:
    Feb 18, 2012
    Posts:
    125
    ^
    |
    |
    |
     
  2. EliteMossy

    EliteMossy

    Joined:
    Dec 2, 2012
    Posts:
    513
    What you mean into rows and columns? string.Split is probably what you want.
     
  3. Errorsatz

    Errorsatz

    Joined:
    Aug 8, 2012
    Posts:
    555
    That would depend on what the contents of the string are. There's a lot of different ways you can represent a grid in a string.
     
  4. D3Jason1

    D3Jason1

    Joined:
    Feb 18, 2012
    Posts:
    125
    i want to be able to call apon 1 csv that has 4 columns and 100+ rows and then take out a certain column from a row
     
  5. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
    What was wrong with the last thread?
    Someone even posted some example script.
    It's string.split...
     
  6. D3Jason1

    D3Jason1

    Joined:
    Feb 18, 2012
    Posts:
    125
    arrays are difficult... ffs it keeps giving me errors and i have no idea how to structure it..

    my current attempt..

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System;
    4. public class test : MonoBehaviour {
    5.    
    6.     IEnumerator Start () {
    7.         string url = "http://www.decadesband.com/uploads/2/8/0/0/2800976/song_data.csv";
    8.         WWW www = new WWW (url);
    9.         yield return www;
    10.         String [7,2] basic = www.text.Split(new Char [] {',','\n'});
    11.         Debug.Log(basic[5,2]);
    12.     }
    13.    
    14.     void Update () {
    15.    
    16.     }
    17. }
    this also doesn't work

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System;
    4. public class test : MonoBehaviour {
    5.    
    6.     IEnumerator Start () {
    7.         string url = "http://www.decadesband.com/uploads/2/8/0/0/2800976/song_data.csv";
    8.         WWW www = new WWW (url);
    9.         yield return www;
    10.        
    11.     }
    12.     public String [7,2] basic = www.text.Split(new Char [] {',','\n'});
    13.     Debug.Log(basic[5,2]);
    14.     void Update () {
    15.    
    16.     }
    17. }
    18.  
     
    Last edited: Mar 23, 2013
  7. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
    You havent said what the errors are, they are usually intuitive (enough)
    Also, with split, pretty sure you can just do string.Split(',' , '\n') without needing to say its an array
    Thisll only give a single dimension array
    then count x number, y number of times, and feed that into a new 2d array