关于unity c#脚本中将string字符串进行分割

来源:互联网 发布:c#集合和数组的区别 编辑:程序博客网 时间:2024/05/16 16:13

笔者在查找的时候,找了好长时间,总会报错 于是自己开始试验 最后发现了一个方法 

using System.Collections;using System.Collections.Generic;using UnityEngine;public class Getdata_uimian : MonoBehaviour {string a="1*12*123*1234|4321*321*21*1";//字符串中添加字符串 我的想法是 先取到'|'分开,放在两个不同数组中string[] astr;string[] astr_b;string[] astr_a;void Start () {astr = a.Split ('|');//将数组a分为两个元素 已'|'为分割单位astr_a = astr [0].Split ('*');将数组astr中第一个元素加入到数组astr_a中   下面如同astr_b = astr [1].Split ('*');foreach (string u in astr_a) {Debug.Log (u);//测试打印出来的是 1 12 123 1234}}// Update is called once per framevoid Update () {}}