Split String in C# and VB.Net

Last Reply 8 months ago By dharmendr

Posted 8 months ago


i have following string i want to break it in 2

string value= 22-52

the  result should be as 

customer id= 22

product id= 52

before - all digits are customer id it can be any 22 23 or 100 or1000 so before - customer and after - it is product id please advice

Posted 8 months ago

Hi nauna,

Use Split function.

Refer below code.


string value = "22-52";
string customerid = value.Split('-')[0];
string productid = value.Split('-')[1];


Dim value As String = "22-52"
Dim customerid As String = value.Split("-"c)(0)
Dim productid As String = value.Split("-"c)(1)