split the string of a row of datatable in asp.net -


i using asp.net. trying split data in datatable. have code sample this:

 {      dt=objerrorloggingdataaccess.geterrordetails(errorid);          string[] stringseparators = new string[] { "message" };         string error = dt.rows[0]["message"].tostring();         string[] test = error.split(stringseparators, stringsplitoptions.none);         string pagename = test[0].tostring();         pagenamelabel.text = pagename;          stringseparators=new string[] {httpcontext.current.request.url.tostring()};         error = dt.rows[0]["message"].tostring();         test = error.split(stringseparators, stringsplitoptions.none);         string message = test[0].tostring();         messagelabel.text = message;} 

in datatable following data there:

 {....id.......message.......................................................................................................................  ....1........http://localhost:10489/images/categoryicon/images    message :   file not exist. username: naresh@naresh.com  ....2........http://localhost:10489/images/categoryicon/images    message : file not exist. username: iswar@iswar.com} 

now problem how can split message , store in label. want

   {http://localhost:10489/images/categoryicon/images} 

separately , username seperately , message seperately. how can do? executing above code able split

  { http://localhost:10489/images/categoryicon/images    } 

only . how can split message column , store in pagelabel, messagelabel, usernamelabel.

thank you

with regard

iswar

i use regular expression in case. because splitting string looks little bit inflexible me.

i tested data example against quick , dirty regex:

(?<id>\d+)\.*(?<url>\w+:\/\/[\w@][\w.:@]+\/?[\w\.?=%&=\-@/$,]*)\s*message\s*:\s*(?<message>.*)username:\s*(?<username>([a-za-z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-za-z0-9\-]+\.)+))([a-za-z]{2,4}|[0-9]{1,3})) 

it supports valid urls , email patterns.

regex regex = new regex(       "(?<id>\\d+)\\.*(?<url>\\w+:\\/\\/[\\w@][\\w.:@]+\\/?[\\w\\.?"+       "=%&=\\-@/$,]*)\\s*message\\s*:\\s*(?<message>.*)username:\\s"+       "*(?<username>([a-za-z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1"+       ",3}\\.[0-9]{1,3}\\.)|(([a-za-z0-9\\-]+\\.)+))([a-za-z]{2,4}|"+       "[0-9]{1,3}))",     regexoptions.ignorecase     | regexoptions.cultureinvariant     | regexoptions.ignorepatternwhitespace     | regexoptions.compiled     );   // capture first match, if any, in inputtext match m = regex.match(inputtext);  // capture matches in inputtext matchcollection ms = regex.matches(inputtext);  // test see if there match in inputtext bool ismatch = regex.ismatch(inputtext);  // names of named capture groups // included fields groups: id, url, message , username string[] groupnames = regex.getgroupnames(); 

i don't know how need call code. maybe in performance troubles if have data. regex q&d - please adjust needs.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -