Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

split web respose c#

Posted on 2009-12-21
8
Medium Priority
?
362 Views
Last Modified: 2012-05-08
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

0
Comment
Question by:JustAskMe
  • 4
  • 3
8 Comments
 
LVL 9

Expert Comment

by:Grant Spiteri
ID: 26098913
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

0
 
LVL 9

Expert Comment

by:Grant Spiteri
ID: 26098922
opps sorry stringSplit should be intialized string.Empty not ""
0
 

Author Comment

by:JustAskMe
ID: 26099012
Same error: Error 1 The best overloaded method match for 'string.Split(params char[])' has some invalid arguments
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:JustAskMe
ID: 26099026
also another errrr can not convert from string to char
0
 

Author Comment

by:JustAskMe
ID: 26099034
Error 2 Argument '1': cannot convert from 'string' to 'char[]'
0
 
LVL 9

Expert Comment

by:Grant Spiteri
ID: 26099172
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.
0
 
LVL 9

Accepted Solution

by:
Grant Spiteri earned 1000 total points
ID: 26099208
But if that is the process you wish to stick to here is an alternative that i have tested and works
string delimiter = "<td><a class=";
            string valueToDelimiteOn = "<td><a class=vcard.php?city=></td><td><a class=asdfasdf</td>";
            string[] stringArray = Regex.Split(valueToDelimiteOn, delimiter);
            string stringSplit = string.Empty;
            foreach (string item in stringArray)
            {
                if (item.Contains("vcard.php?city="))
                {
                    stringSplit = item;
                    break;
                }
            }
0
 
LVL 13

Assisted Solution

by:Ashok
Ashok earned 1000 total points
ID: 26099335
Hi JustAskMe,

The link I provided in your earlier question http://dotnetperls.com/string-split has following.....

Multiple characters
Here we use either the Regex method or the C# new array syntax. Note that a new char array is created in the following usages. There is an overloaded method with that signature if you need StringSplitOptions, which is used to remove empty strings.

=== Program that splits on lines with Regex (C#) ===

using System;
using System.Text.RegularExpressions;

class Program
{
    static void Main()
    {
        string value = "cat\r\ndog\r\nanimal\r\nperson";
        //
        // Split the string on line breaks.
        // The return value from Split is a string[] array.
        //
        string[] lines = Regex.Split(value, "\r\n");

        foreach (string line in lines)
        {
            Console.WriteLine(line);
        }
    }
}

So gspiteri is right, his solution would work.

HTH
Ashok
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question