i want split url 2 part using regex. have saved xml response datatable , iterate through each row using foreach. when use datatable value regex 0 available. when use array index 1 give following exception.
system.indexoutofrangeexception: index outside bounds of array. the following gives , exception.
foreach (datarow row in ndt.rows) { string imgurl =row["image1"].tostring(); string[] fimgurl = regex.split(imgurl, @"small/"); string simgurl = fimgurl[1]; } the following it's working without issue.
foreach (datarow row in ndt.rows) { //textbox1.text = row["imagepath"].tostring(); string imgurl ="http://www.hotelbeds.com/giata/small/12/124356/124356a_hb_w_001.jpg"; string[] fimgurl = regex.split(imgurl, @"small/"); string simgurl = fimgurl[1]; } i have saved same url string in datatable. couldn't find what's wrong that. can please me on this?
some people, when confronted problem, think "i know, i'll use regular expressions." have 2 problems. --jamie zawinski
var uri = new uri("http://www.hotelbeds.com/giata/small/12/124356/124356a_hb_w_001.jpg"); var firstpart = uri.host + string.concat(uri.segments.take(3)); // returns: "www.hotelbeds.com/giata/small/" var lastpart = string.concat(uri.segments.skip(3)); // returns: "12/124356/124356a_hb_w_001.jpg" if need http, can use uri.scheme. change 3 other number if want split in different place.
additionally can search uri.segments index of directory want if changes.
Comments
Post a Comment