Click here to Skip to main content
15,898,374 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted

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)
 
Share this answer
 
Try this code. Change the size to limit you want.

C#
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);
}
 
Share this answer
 
v2
Comments
kanna443 5-Sep-13 10:37am    
Thanks ArunRajendra.

but this should be done my DAL file before going to pass my id.

will it possible
ArunRajendra 5-Sep-13 23:54pm    
I don't see any reason why it cannot be done in DAL and passed back.
kanna443 9-Sep-13 6:40am    
working fine thank you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900