Reputation: 443
This is the code:
string firsttag = "\"";
string endtag = "\",\"";
int start;
int end;
for (int i = 0; i < images.Length; i++)
{
start = images.IndexOf(firsttag);
end = images.IndexOf(endtag, start);
string h = images.Substring(start + firsttag.Length, end - start - firsttag.Length);
start = images.IndexOf(firsttag, end + 1);
}
This is the string content:
"http://www.niederschlagsradar.de/images.aspx?jaar=-6&type=europa.cld&datum=201311161500&cultuur=en-GB&continent=europa","http://www.niederschlagsradar.de/images.aspx?jaar=-6&type=europa.cld&datum=201311161800&cultuur=en-GB&continent=europa"
What i get in the variable h is:
http://www.niederschlagsradar.de/images.aspx?jaar=-6&type=europa.cld&datum=201311161500&cultuur=en-GB&continent=europa
But im getting in any loop/itertion the same line/string what i want to do is to get all the links from the variable images then i will do map.Images.Add(link); so in the end Images(List) will contain only the links from the string without the " and the , chars.
My question is why in the next itertion i get the same link parsed string and not the next one untill the last one ? And i want to use indexof and substring.
In general im getting the link the first one without the chars " and , But i dont get the next one untill the end it keep giving me the same one all the time.
Upvotes: 0
Views: 106
Reputation: 841
Split the images string into an array and then traverse the array, deleting occurances of ":
var entries = images.Split(new[] {','});
for (var i = 0; i < entries.Length; i++)
entries[i] = entries[i].Replace("\"", "");
Upvotes: 0
Reputation: 498942
The following makes a few assumptions:
inputString.Trim('"').Split(new []{"\",\""}, StringSplitOptions.None)
That the input string starts and ends with single "
characters and that ","
is the delimiter between URIs (meaning, it is always that and that this substring doesn't appear anywhere inside a URI).
Note, that if you wish to further parse each URI, you can use the Uri
class to get a strongly typed parse of the string.
Upvotes: 3