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.Check if string starts with specific string in C# and VB.Net<p>Hi <a class="username" rel="irshad1231"> irshad1231</a>,</p> <p>Check this example. Now please take its reference and correct your code.</p> <p><strong><span style="text-decoration: underline;">C#</span></strong></p> <pre class="brush: csharp">string mobileno = &#34;966123456789&#34;; string finalmobileno = &#34;&#34;; if (mobileno.StartsWith(&#34;966&#34;)) //starting with 966 { finalmobileno = Regex.Replace(mobileno, &#34;^966&#34;, &#34;&#34;, RegexOptions.IgnoreCase); // Replace starting 966. } Response.Write(finalmobileno.ToString() + &#34;&lt;br/&gt;&#34;); string iqamano = &#34;0123456789&#34;; if (iqamano.StartsWith(&#34;0&#34;)) //starting with 0 { finalmobileno = Regex.Replace(iqamano, &#34;^0&#34;, &#34;&#34;, RegexOptions.IgnoreCase); // Replace starting 0. } Response.Write(finalmobileno.ToString());</pre> <p><strong><span style="text-decoration: underline;">VB.Net</span></strong></p> <pre class="brush: vb">Dim mobileno As String = &#34;966123456789&#34; Dim finalmobileno As String = &#34;&#34; If mobileno.StartsWith(&#34;966&#34;) Then &#39;starting with 966 finalmobileno = Regex.Replace(mobileno, &#34;^966&#34;, &#34;&#34;, RegexOptions.IgnoreCase) &#39;Replace starting 966. End If Response.Write(finalmobileno.ToString() &amp; &#34;&lt;br/&gt;&#34;) Dim iqamano As String = &#34;0123456789&#34; If iqamano.StartsWith(&#34;0&#34;) Then &#39;starting with 0 finalmobileno = Regex.Replace(iqamano, &#34;^0&#34;, &#34;&#34;, RegexOptions.IgnoreCase) &#39;Replace starting 0. End If Response.Write(finalmobileno.ToString())</pre> <p><strong><span style="text-decoration: underline;">Output</span></strong></p> <p>123456789</p> <p>123456789</p>https://www.aspforums.net:443/Threads/104798/Check-if-string-starts-with-specific-string-in-C-and-VBNet/https://www.aspforums.net:443/Threads/104798/Check-if-string-starts-with-specific-string-in-C-and-VBNet/Thu, 22 Aug 2019 03:17:52 GMTCheck if string starts with specific string in C# and VB.Net<p>Try this without Regex simple and easy.</p> <pre class="brush: csharp">string mobileno = &#34;966123456789&#34;; string finalmobileno = &#34;&#34;; if (mobileno.StartsWith(&#34;966&#34;)) //starting with 966 { finalmobileno = mobileno.Substring(mobileno.IndexOf(&#34;966&#34;) +3); } lbl_mobile.Text = finalmobileno.ToString(); string iqamano = &#34;0123456789&#34;; if (iqamano.StartsWith(&#34;0&#34;)) //starting with 0 { finalmobileno = iqamano.Substring(iqamano.IndexOf(&#34;0&#34;) +1); } lbl_mobile.Text = finalmobileno.ToString();</pre>https://www.aspforums.net:443/Threads/104798/Check-if-string-starts-with-specific-string-in-C-and-VBNet/https://www.aspforums.net:443/Threads/104798/Check-if-string-starts-with-specific-string-in-C-and-VBNet/Thu, 22 Aug 2019 03:29:08 GMTCheck if string starts with specific string in C# and VB.Net<p>I'm doing this&nbsp;as below. It's working.</p> <pre class="brush: csharp">if (mobileno.StartsWith(&#34;966&#34;)) { lbl_mobile.Text = mobileno.Remove(0, 3); } else { lbl_mobile.Text = mobileno.Remove(0, 1); }</pre> <p>&nbsp;</p> <p>&nbsp;</p> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/104798/Check-if-string-starts-with-specific-string-in-C-and-VBNet/https://www.aspforums.net:443/Threads/104798/Check-if-string-starts-with-specific-string-in-C-and-VBNet/Thu, 22 Aug 2019 03:36:30 GMT