ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Retrieve Number from String using Regular Expression in C# and VB.Net<p>Hi <a class="username" rel="PRA"> PRA</a>,</p> <p>Refer below code.</p> <p><strong><span style="text-decoration: underline;">C#</span></strong></p> <pre class="brush: csharp">protected void Page_Load(object sender, EventArgs e) { string selected = &#34;&#34;; string selectedValues = &#34;Let me introduce myself&infin;1My full name is Andrei Andreevich Ivanov&infin;2I was named after my father and I am very happy about it&infin;3I was born on April, 7, 1981 in Moscow&infin;4I come from the family of office workers&infin;5I am an only child in the family&infin;6I am a pupil of the eleventh form of a secondary school&infin;7 I&#39;m finishing school this year&infin;8I want to enter the University of Moscow&infin;9That is why I have to study twice as hard as an ordinary pupil&infin;10I&#39;m not only doing my best at school, I&#39;m taking a preparatory course at the University&infin;11&#34;; foreach (string item in selectedValues.Split(&#39;&infin;&#39;)) { string number = System.Text.RegularExpressions.Regex.Match(item, @&#34;\d+&#34;).Value; if (!string.IsNullOrEmpty(number)) { selected += number + &#34;,&#34;; } } Response.Write(selected.TrimEnd(&#39;,&#39;)); }</pre> <p><strong><span style="text-decoration: underline;">VB.Net</span></strong></p> <pre class="brush: vb">Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load Dim selected As String = &#34;&#34; Dim selectedValues As String = &#34;Let me introduce myself&infin;1My full name is Andrei Andreevich Ivanov&infin;2I was named after my father and I am very happy about it&infin;3I was born on April, 7, 1981 in Moscow&infin;4I come from the family of office workers&infin;5I am an only child in the family&infin;6I am a pupil of the eleventh form of a secondary school&infin;7 I&#39;m finishing school this year&infin;8I want to enter the University of Moscow&infin;9That is why I have to study twice as hard as an ordinary pupil&infin;10I&#39;m not only doing my best at school, I&#39;m taking a preparatory course at the University&infin;11&#34; For Each item As String In selectedValues.Split(&#34;&infin;&#34;c) Dim number As String = System.Text.RegularExpressions.Regex.Match(item, &#34;\d+&#34;).Value If Not String.IsNullOrEmpty(number) Then selected += number &amp; &#34;,&#34; End If Next Response.Write(selected.TrimEnd(&#34;,&#34;c)) End Sub</pre> <p><strong><span style="text-decoration: underline;">Output</span></strong></p> <p>1,2,3,4,5,6,7,8,9,10,11</p>https://www.aspforums.net:443/Threads/126839/Retrieve-Number-from-String-using-Regular-Expression-in-C-and-VBNet/https://www.aspforums.net:443/Threads/126839/Retrieve-Number-from-String-using-Regular-Expression-in-C-and-VBNet/Fri, 05 Oct 2018 04:14:09 GMT