c# - Dropdown SelectedItem.Value with a different text -


i have dropdownlist textm use half of phrase how can easy? show code, right can full text.

i want take hours in text: 1hr, 24hrs. delete text.

example:text="send reminder 1hr before"

so want that: text="1hr"

i want take hour , guys

<asp:dropdownlist id="reminderoptions" runat="server">     <asp:listitem value="-1" text="don't send reminder" />     <asp:listitem value="3600" text="send reminder 1hr before" />     <asp:listitem value="86400" text="send reminder 24hrs before" /> </asp:dropdownlist> lblreminderset.text = reminderoptions.selecteditem.value; lblreminderset.text = string.format("a message sent {0} lessons", reminderoptions.selecteditem.text); 

let's use regex pull time frame out:

(\d+hr[s]?) 

regular expression visualization

debuggex demo

this expression says find me digit, 1 or more times, followed hr, optionally followed s. now, use might this:

var match = regex.match(reminderoptions.selecteditem.text, @"(\d+hr[s]?)"); if (match.success) {     var hrs = match.groups[1];     lblreminderset.text = string.format(         "a message sent {0} lessons", hrs); } 

now, if want word before can modify regex slightly:

(\d+hr[s]? before) 

and grab part of match.


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -