c# - Parsing a string to extract a URL or folder path -
i asked similar question using regex retrieve url or folder path string. looking @ comment dour high arch, says:
"i recommend not use regexes @ all; use separate code paths urls, using uri class, , file paths, using fileinfo class. these classes handle parsing, matching, extracting components, , on."
i never tried this, looking , can't figure out if said useful i'm trying accomplish.
i want able parse string message like:
"i placed files on server @ http://www.thewebsite.com/newstuff, can reached on local network drives @ j:\downloads\newstuff"
and extract out 2 strings http://www.thewebsite.com/ , j:\downloads\newstuff. don't see methods on uri or fileinfo class parse uri or fileinfo object string think dour high arch implying.
is there i'm missing using uri or fileinfo class allow behavior? if not there other class in framework this?
i'd easiest way splitting strings parts first.
first delimiter spaces, each word - second qoutes (double , single)
then use uri.iswellformeduristring on each token.
so like:
foreach(var part in string.split(new char[]{''', '"', ' '}, somerandomtext)) { if(uri.iswellformeduristring(part, urikind.relativeorabsolute)) dosomethingwith(part); } just saw @ uri.isewellformeduristring bit strickt suit needs maybe. returns false if www.whatever.com missing http://
Comments
Post a Comment