Click here to Skip to main content
15,899,313 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello friends,
I have clientid and comma separated string (a,b,c).
How can I get comma separated string in an array?
How can I save every part of string into the database?

Any idea?

Thanks in advance
Posted
Updated 4-Aug-11 1:09am
v2
Comments
dhage.prashant01 4-Aug-11 7:24am    
I want it to take in array list, so that later it helps me to save each element of array into the database

Any idea, how can I do it?

Try as below.

For C#
C#
string input = "1,2,3,4,5";
string[] stringArray = input.Split(',');


For Javascript
JavaScript
var mySplitResult = myString.split(",");
 
Share this answer
 
v4
Try this.
string[] arr;
arr = "123,456,678".Split(',');


OP: I'm doing code in VB.NET tell me, user enters a,b,c,d in text box, how can I insert a b c d separately into database
Dim arr As String()
arr = "123,456,789".Split(",")

Dim strval As String = ""
For i As Integer = 0 To arr.Length - 1
  strval = arr(i)
  // do your insert operation here 
Next
 
Share this answer
 
v2
Comments
dhage.prashant01 4-Aug-11 7:24am    
I want it to take in array list, so that later it helps me to save each element of array into the database

Any idea, how can I do it?
Toniyo Jackson 4-Aug-11 7:33am    
This also you can use like this. arr[0],arr[1],arr[2],arr[3]...
dhage.prashant01 4-Aug-11 7:39am    
Problem is I don't know the size of array in advance
for example I have string a,b,c,d
I want to save it in array as u said
but how can i determine the size?
Toniyo Jackson 4-Aug-11 7:41am    
arr.Length
dhage.prashant01 4-Aug-11 7:44am    
You did not get my point.
when you declare array, to need to mention its size.
but in my case, i don't have idea about size in advance.
User can input any text in comma separated format and each part of string I wan to save into database
You can use string.Split() method. This will return an array of strings.
 
Share this answer
 
v2
Hiii
Try this
string.split()...............................
 
Share this answer
 
Comments
Manfred Rudolf Bihy 12-Aug-11 11:01am    
Your '.' key is stuck again?
dhage.prashant01 8-Feb-12 0:45am    
lolz..

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