123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- public class StringUtil
- {
- public static string[] Split(string str, char c)
- {
- if(Empty(str))
- return new string[0];
- return str.Split(new char[]{c});
- }
- public static int[] SplitToInt(string str, char c)
- {
- if(Empty(str))
- return new int[0];
- string[] strArr = Split(str, c);
- int[] intArr = new int[strArr.Length];
- for(int i=0; i<strArr.Length; i++)
- {
- intArr[i] = ToInt(strArr[i]);
- }
- return intArr;
- }
- public static float[] SplitToFloat(string str, char c)
- {
- if(Empty(str))
- return new float[0];
- string[] strArr = Split(str, c);
- float[] floatArr = new float[strArr.Length];
- for(int i=0; i<strArr.Length; i++)
- {
- floatArr[i] = ToFloat(strArr[i]);
- }
- return floatArr;
- }
- public static bool Empty(string str)
- {
- return str == null || str == "";
- }
- public static string FillZero(string str, int count)
- {
- str = "0000000000000000"+str;
- str = str.Substring(str.Length-count, count);
- return str;
- }
- public static string FillZero(int value, int count)
- {
- return FillZero(value.ToString(), count);
- }
- public static int ToInt(string str)
- {
- if(StringUtil.Empty(str))
- {
- return 0;
- }
- return int.Parse(str);
- }
- public static float ToFloat(string str)
- {
- if(StringUtil.Empty(str))
- {
- return 0;
- }
- return float.Parse(str);
- }
- public static bool ToBool(string str)
- {
- str = str.ToLower();
- if(str == "true")
- {
- return true;
- }
- else if(str == "false")
- {
- return false;
- }
- int value = ToInt(str);
- if(value > 0)
- return true;
- return false;
- }
- public static string Join(List<string> list, string separator)
- {
- string str = "";
- for (int i = 0; i < list.Count; i++)
- {
- str += list[i];
- if (i < list.Count - 1)
- str += separator;
- }
- return str;
- }
- }
|