Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
288 views
in Technique[技术] by (71.8m points)

c# - How do i parse a string?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...