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.Replace First and Last characters from String in C# and VB.Net<p>Hi <a class="username" rel="SUJAYS"> SUJAYS</a>,</p> <p>Please refer below sample.</p> <p><span style="text-decoration: underline;"><strong>Code</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">protected void Page_Load(object sender, EventArgs e) { string oldchar = &#34;TSPForums.nea&#34;; string outcome = ReplaceLeft(oldchar); string finaloutcom = ReplaceRight(outcome); Response.Write(&#34;&lt;b&gt;&#34; + oldchar + &#34;&lt;/b&gt;&#34; + &#34; After replacing left and right characters &lt;b&gt;&#34; + finaloutcom + &#34;&lt;/b&gt;&#34;); } public string ReplaceLeft(string oldcharacterLeft) { string result1 = oldcharacterLeft.Replace(oldcharacterLeft.Substring(0, oldcharacterLeft.Length + 1 - oldcharacterLeft.Length), &#34;A&#34;); return result1; } public string ReplaceRight(string oldchrRight) { string result2 = oldchrRight.Replace(oldchrRight.Substring(oldchrRight.Length - 1), &#34;t&#34;); return result2; }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load Dim oldchar As String = &#34;TSPForums.nea&#34; Dim outcome As String = ReplaceLeft(oldchar) Dim finaloutcom As String = ReplaceRight(outcome) Response.Write(&#34;&lt;b&gt;&#34; &amp; oldchar &amp; &#34;&lt;/b&gt;&#34; &amp; &#34; After replacing left and right characters &lt;b&gt;&#34; &amp; finaloutcom &amp; &#34;&lt;/b&gt;&#34;) End Sub Public Function ReplaceLeft(ByVal oldcharacterLeft As String) As String Dim result1 As String = oldcharacterLeft.Replace(oldcharacterLeft.Substring(0, oldcharacterLeft.Length + 1 - oldcharacterLeft.Length), &#34;A&#34;) Return result1 End Function Public Function ReplaceRight(ByVal oldchrRight As String) As String Dim result2 As String = oldchrRight.Replace(oldchrRight.Substring(oldchrRight.Length - 1), &#34;t&#34;) Return result2 End Function</pre> <p><span style="text-decoration: underline;"><strong>Output</strong></span></p> <p><strong>TSPForums.nea</strong> After replacing left and right characters <strong>ASPForums.net</strong></p>https://www.aspforums.net:443/Threads/720288/Replace-First-and-Last-characters-from-String-in-C-and-VBNet/https://www.aspforums.net:443/Threads/720288/Replace-First-and-Last-characters-from-String-in-C-and-VBNet/Tue, 19 Feb 2019 23:20:09 GMT