123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using UnityEngine;
- /// <summary>
- /// 字符串分割相关工具集
- /// </summary>
- public partial class Utils
- {
- /// <summary>
- /// 序列化指定目标, 逗号分隔符
- /// </summary>
- /// <param name="buff">目标数据</param>
- /// <returns>序列化后字符串</returns>
- public static string SeralizeToDotString(int[] buff)
- {
- string tmp = string.Empty;
- for (int i = 0; i < buff.Length; ++i)
- {
- tmp += buff[i];
- tmp += ",";
- }
- return tmp;
- }
- /// <summary>
- /// 序列化指定目标, 逗号分隔符
- /// </summary>
- /// <param name="buff">目标数据</param>
- /// <returns>序列化后字符串</returns>
- public static string SeralizeToDotString(List<int> buff)
- {
- string tmp = string.Empty;
- for (int i = 0; i < buff.Count; ++i)
- {
- tmp += buff[i];
- tmp += ",";
- }
- return tmp;
- }
- /// <summary>
- /// 反序列化逗号分割字符串
- /// </summary>
- /// <param name="from">字符串</param>
- /// <param name="dst">目标缓冲区</param>
- public static void UnserializeDotString(string from, ref int[] dst)
- {
- string[] split = from.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
- for (int i = 0; i < split.Length; ++i)
- {
- dst[i] = Convert.ToInt32(split[i]);
- }
- }
- /// <summary>
- /// 反序列化逗号分割字符串
- /// </summary>
- /// <param name="from">字符串</param>
- /// <param name="dst">目标缓冲区</param>
- public static void UnserializeDotString(string from, ref List<int> dst)
- {
- string[] split = from.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
- for (int i = 0; i < split.Length; ++i)
- {
- dst.Add(Convert.ToInt32(split[i]));
- }
- }
- /// <summary>
- /// 反序列化逗号分割字符串
- /// </summary>
- /// <param name="from">字符串</param>
- /// <returns>反序列化后列表</returns>
- public static List<int> UnserializeDotString(string from)
- {
- List<int> dst = new List<int>();
- string[] split = from.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
- for (int i = 0; i < split.Length; ++i)
- {
- dst.Add(Convert.ToInt32(split[i]));
- }
- return dst;
- }
- /// <summary>
- /// 反序列化逗号分割字符串
- /// </summary>
- /// <param name="from">字符串</param>
- /// <returns>反序列化后列表</returns>
- public static List<double> UnserializeDotStringToDouble(string from)
- {
- List<double> dst = new List<double>();
- string[] split = from.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
- for (int i = 0; i < split.Length; ++i)
- {
- dst.Add(double.Parse(split[i]));
- }
- return dst;
- }
- /// <summary>
- /// 反序列化逗号分割字符串
- /// </summary>
- /// <param name="from">字符串</param>
- /// <returns>反序列化后列表</returns>
- public static List<string> UnserializeDotStringToString(string from)
- {
- List<string> dst = new List<string>();
- string[] split = from.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
- for (int i = 0; i < split.Length; ++i)
- {
- dst.Add(split[i]);
- }
- return dst;
- }
- }
|