service2001
asked on
how to split string text in asp.net
i have a string something like this:
"dp@Duplicate Passport;sp@Stolen Passport;"
how do i split to like this:
dp = Duplciate Passport
sp = Stoled Passport
i'm using asp.net 2
c#
thanks.
"dp@Duplicate Passport;sp@Stolen Passport;"
how do i split to like this:
dp = Duplciate Passport
sp = Stoled Passport
i'm using asp.net 2
c#
thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
string strToSplit = "dp@Duplicate Passport;sp@Stolen Passport;";
string[] items = strToSplit.Split(";");
foreach(string item in items)
{
string[] ask = item.Split("@");
// ask[0] will = "dp"
// ask[1] will = "Duplicate Passport"
// and it repeats. What you do with it, would be up to you or how you want to store it.
}
string[] items = strToSplit.Split(";");
foreach(string item in items)
{
string[] ask = item.Split("@");
// ask[0] will = "dp"
// ask[1] will = "Duplicate Passport"
// and it repeats. What you do with it, would be up to you or how you want to store it.
}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
guys sorry for late response
but here is what im doing and it throwing me error
Cannot convert type 'string' to 'string[]'
stringbuilder sb = new stringbuilder();
foreach (string key in Request.QueryString.Keys) //get the url string from querystring
{
//items data looks like this: "SP;ADP;FDD;DFD";
string items = Request[key];
string[] itemsarray = (string[])items;
foreach (string item in items)
{
string[] x = item.Split(';');
if (string[0] == "SP")
{
sb.append("sp = stolen passport");
}
if (string [1] == "ADP")
{
sb.append("adp = active directory project");
}
}
}
any help ?
thanks
but here is what im doing and it throwing me error
Cannot convert type 'string' to 'string[]'
stringbuilder sb = new stringbuilder();
foreach (string key in Request.QueryString.Keys) //get the url string from querystring
{
//items data looks like this: "SP;ADP;FDD;DFD";
string items = Request[key];
string[] itemsarray = (string[])items;
foreach (string item in items)
{
string[] x = item.Split(';');
if (string[0] == "SP")
{
sb.append("sp = stolen passport");
}
if (string [1] == "ADP")
{
sb.append("adp = active directory project");
}
}
}
any help ?
thanks
ASKER
also i dont like the idea of hardcoding the string[0] or string[1] rather i would like to put in the loop
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I returned and gave further answers. Recommend I at least get some points.
Ben.
Ben.
ASKER
thanks.