失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > C#将数组转换为字符串 且将字符串分割存入数组中

C#将数组转换为字符串 且将字符串分割存入数组中

时间:2019-07-08 21:54:18

相关推荐

C#将数组转换为字符串 且将字符串分割存入数组中

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace 数组{class Program{static void Main(string[] args){DateTime bt = System.DateTime.Now;double[] a =new double[3] {1,2,3};string c = string.Join(",",a);double[,] b = new double[38, 183];//Console.WriteLine(b.GetLength(0));for(int i = 0; i < b.GetLength(0); i++){for (int j = 0; j < b.GetLength(1); j++){b[i, j] = i + j;}}double[,] zzz= new double[50, 300];//Console.WriteLine(b.GetLength(0));for (int i = 0; i < zzz.GetLength(0); i++){for (int j = 0; j < zzz.GetLength(1); j++){zzz[i, j] = i + j;}}//Console.WriteLine(b.GetLength(1));//Console.WriteLine(sz.zzfc(b));string lll = sz.zzfc(b);double[,] cc = sz.cfsz(sz.zzfc(b));string llll = sz.zzfc(zzz);double[,] ccc = sz.cfsz(sz.zzfc(zzz));llll = sz.zzfc(zzz);ccc = sz.cfsz(sz.zzfc(zzz));llll = sz.zzfc(zzz);ccc = sz.cfsz(sz.zzfc(zzz));Console.WriteLine(c);DateTime ht = System.DateTime.Now;TimeSpan ts = ht.Subtract(bt);Console.WriteLine("共花费{0}ms",ts.TotalMilliseconds);Console.ReadKey();}}public class sz{/// <summary>/// 输入一个多维数组将其转换为字符串/// </summary>/// <param name="sz"></param>/// <returns></returns>public static string zzfc(double [,] sz){string a = "^";//数组行隔离符号string zfc=string.Empty;double[] zhsz = new double[sz.GetLength(1)];//获得中间数组的维度,为原始数组列数for (int j=0;j<sz.GetLength(0); j++){for (int i = 0; i < sz.GetLength(1); i++){zhsz[i] = sz[j,i];}zfc += string.Join(",", zhsz);if (j == sz.GetLength(0) - 1){zfc = zfc;}else{zfc = zfc + a;}}return zfc;}/// <summary>/// 输入一个字符串,将其拆分为数组,类型为double/// </summary>/// <param name="zfc"></param>/// <returns></returns>public static double [,] cfsz (string zfc){string[] hs = zfc.Split('^');string[] ls =hs[0].Split(',');int hss = hs.Length;//获得拆分数组行数int lss = ls.Length;//获得拆分数组列数double[,] sz = new double[hss,lss];for (int i=0; i < hss; i++){ls = hs[i].Split(',');for (int j=0; j < lss; j++){sz[i, j] = Convert.ToDouble(ls[j]);}}return sz;}/// <summary>/// 字符串转为数组,返回类型为string/// </summary>/// <param name="zfc"></param>/// <returns></returns>public static string[,] CFsz (string zfc){string[] hs = zfc.Split('^');string[] ls = hs[0].Split(',');int hss = hs.Length;//获得拆分数组行数int lss = ls.Length;//获得拆分数组列数string [,] sz = new string [hss, lss];for (int i = 0; i < hss; i++){ls = hs[i].Split(',');for (int j = 0; j < lss; j++){sz[i, j] = ls[j];}}return sz;}}}

如果觉得《C#将数组转换为字符串 且将字符串分割存入数组中》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。