Link to home
Start Free TrialLog in
Avatar of JustAskMe
JustAskMe

asked on

split web respose c#

I Want to split the respose that for each "<td><a class="; it should give me a new string

my code doesn't work...

any idea?
string D = "<td><a class=";
            char[] delimiter = D.ToCharArray();
            string[] SL = Response.Split(delimiter);
            int I = 0;
            string S = "";
            foreach (string S1 in SL)
            {
                if (S1.Contains("vcard.php?city="))
                {
                    S = S1;
                    break; // TODO: might not be correct. Was : Exit For
                }
                I = +1;
            }

Open in new window

Avatar of Grant Spiteri
Grant Spiteri
Flag of Australia image

From what i can  see first thing is your actually splitting your delimiter instead of an actual value,
there is no need for the variable i, and while your splitting your delimiinter it will never step into your if statement.


string delimiter = "<td><a class=";
            string valueToDelimiteOn = "<td><a class=blah blah></td><td><a class=asdfasdf</td>"; 
            string[] stringArray = valueToDelimiteOn.Split(delimiter);
            string stringSplit = "";
            foreach (string item in stringArray)
            {
                if (item.Contains("vcard.php?city="))
                {
                    stringSplit  = item;
                    break; 
                }
            }

Open in new window

opps sorry stringSplit should be intialized string.Empty not ""
Avatar of JustAskMe
JustAskMe

ASKER

Same error: Error 1 The best overloaded method match for 'string.Split(params char[])' has some invalid arguments
also another errrr can not convert from string to char
Error 2 Argument '1': cannot convert from 'string' to 'char[]'
my apologies its abit early for me the issue is that when converting the delimiter string to char array it separates each character which is not what you want my understanding of what you want seems to be that your checking for values and if they are present you wish to store in a string ie:
 if (item.Contains("vcard.php?city="))
                {
                    stringSplit = item;
                    break;
                }

could you please elaborate further as to what your trying to achieve so perhaps i can suggest an alternative method to implementing it.
ASKER CERTIFIED SOLUTION
Avatar of Grant Spiteri
Grant Spiteri
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Ashok
Ashok
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial