c# - How do I only get the year? -
i have following code:
string ship = "";  foreach (htmlelement el in webbrowser1.document.getelementsbytagname("div"))     if (el.getattribute("classname") == "not-annotated hover")     {         ship = el.innertext;          int startpos = ship.lastindexof("ship date:") + "ship date:".length + 1;         int length = ship.indexof("country:") - startpos;         string sub = ship.substring(startpos, length);          textbox3.text = sub;     }   this date textbox3.
let's string sub may 19, 2013, how year of string , take int?
note: date changes!
assuming extraction of date part sub correct existing cases, can use datetime.parse() parse date datetime , access year:
int year = datetime.parse(sub).year;      
Comments
Post a Comment