Reputation: 415
i am getting cookie value as parameter .I need to split the cookie value(name,value).
string Cookie ="secureToken_sdfsdfbsadbfsdhbh = Tdne68JhO5baix2Ey_K0ICV1HAAFvUP5BA==";
string[] cookieData = Cookie.Split('=')
It's even taking the last equal character also.I need following output.
cookie[0]=secureToken_sdfsdfbsadbfsdhbh
cookie[1]= Tdne68JhO5baix2Ey_K0ICV1HAAFvUP5BA==
It should consider only the first equal character.after that it shouldn't spilt the string
Upvotes: 0
Views: 86
Reputation: 41
string str= "secureToken_sdfsdfbsadbfsdhbh = Tdne68JhO5baix2Ey_K0ICV1HAAFvUP5BA==";
string[] separator = { " = " };
string[] strarr = str.Split(separator, StringSplitOptions.None);
foreach (string s in strarr)
{
Console.WriteLine(s);
}
Console.ReadKey();
Upvotes: 0
Reputation: 98810
string Cookie ="secureToken_sdfsdfbsadbfsdhbh = Tdne68JhO5baix2Ey_K0ICV1HAAFvUP5BA==";
string[] cookieData = Cookie.Split(new string[] {" = "}, StringSplitOptions.RemoveEmptyEntries);
foreach (var item in cookieData)
{
Console.WriteLine(item);
}
Output will be;
secureToken_sdfsdfbsadbfsdhbh
Tdne68JhO5baix2Ey_K0ICV1HAAFvUP5BA==
Here a Demonstration
.
EDIT: Since you only want 2 split part, limiting will be better as a solution explained in wudzik answers.
Upvotes: 1
Reputation: 23107
use:
Cookie.Split(new char[] { '=' }, 2)
it will limit your split to 2 strings
Upvotes: 4