拆分我的变量值 [英] split my variable values

查看:117
本文介绍了拆分我的变量值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个变量,即var1,其中包含我的患者ID。

像这样103,106,159,4258,......



i需要根据,(逗号)分割前1000个ID的var1并将其存储到另一个变量中,然后将1001到2000分割为另一个变量。



你能为这个

解决方案

提供解决方案你可以在一个数组中拆分整个字符串然后你可以在C#中使用Array.Copy方法从一个数组中复制值到另一个。检查以下链接



如何将数组的一部分复制到C#中的另一个数组? [ ^ ]



C#数组,获取子数据-array from a existing array [ ^ ] javascript:void(0)


试试这段代码。将大小更改为您想要的限制。



  const   int  size =  2 ; 
string s = 103,106,159,4258, 888\" ;

string [] s1 = s.Split(' );
List< array> s2 = new List< array>();
for int i = 0 ; i< s1.length; i> {
数组temp = Array.CreateInstance( typeof string ),size);
Array.Copy(s1,i,temp, 0 ,(i + size > s1.Length?s1.Length - i:size));
s2.Add(temp);
}


i have a variable ie "var1" which contains my patient ids.
like this 103,106,159,4258,......

i need to split the "var1" for first 1000 ids based on ","(comma) and store into another variable,and next 1001 to 2000 to another variable.

can you give solution for this

解决方案

You can split whole string in an array then you can use Array.Copy method in C# to copy values from one array to another. Check below link

How to copy part of an array to another array in C#?[^]

C# arrays , Getting a sub-array from an existing array[^]javascript:void(0)


Try this code. Change the size to limit you want.

const int size = 2;
string s = "103,106,159,4258,888";

string []s1 = s.Split(',');
List<array> s2 = new List<array>();
for(int i=0;i<s1.length;i>            {
    Array temp = Array.CreateInstance(typeof(string), size);
    Array.Copy(s1, i, temp, 0, (i + size > s1.Length ? s1.Length - i : size));
    s2.Add(temp);
}


这篇关于拆分我的变量值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆