× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

Dropdown SelectedItem.Value with a diferent text

Michael Perrenoud
Feb 06, 2015
<p>Let's say we use a Regex to pull that time frame out:</p> <pre><code>(\d+hr[s]?) </code></pre> <p><img src="https://www.debuggex.com/i/KH0LyevInaAoUVjX.png" alt="Regular expression visualization"></p> <p><a href="https://www.debuggex.com/r/KH0LyevInaAoUVjX">Debuggex Demo</a></p> <p>This expression says find me any digit, one or more times, followed by <code>hr</code>, optionally followed by <code>s</code>. Now, to use this you might do something like this:</p> <pre><code>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 to you {0} your lessons", hrs); } </code></pre> <p>Now, if you also want the word <code>before</code> you can modify the Regex slightly:</p> <pre><code>(\d+hr[s]? before) </code></pre> <p>and grab that as part of the match.</p> <p>This tip was originally posted on <a href="http://stackoverflow.com/questions/24118078/Dropdown%20SelectedItem.Value%20with%20a%20diferent%20text/24118207">Stack Overflow</a>.</p>
comments powered by Disqus