title: Formatting textbox.text specific format like : ##.###.###/####-##
body: <p>I need a format like this for 14 chars:</p>
  <blockquote>
  <p>10.257.938/0001.45</p>
  </blockquote>
  <p>But when I execute this code, I get</p>
  <blockquote>
  <h2>.###.###/####-</h2>
  </blockquote>
  <p>on my <code>txtcnpj.text</code>.</p>
  <p>I really don't like to use maskedbox.
  Here's my code (on lost focus.):</p>
  <pre><code>Private Sub txtcnpj_LostFocus(sender As Object, e As EventArgs) Handles txtcnpj.LostFocus
  
          If Len(txtcnpj.Text) &gt; 0 Then
  
              Select Case Len(txtcnpj.Text)
  
                  Case Is = 11
                      txtcnpj.Text = Format(txtcnpj.Text, &quot;###.###.###-##&quot;)
  
                  Case Is = 14
                      txtcnpj.Text = Format(txtcnpj.Text, &quot;##.###.###/####-##&quot;)
                      
              End Select
          End If
      End Sub
  </code></pre>
  <p><a href="https://i.imgur.com/KzZKQuV.png" rel="nofollow noreferrer">OR WHEN I USED ##.###.###/####-##</a>
  RETURN</p>
  <p>SOLVED BY Andrew Morton,
  TY ANDREW . UHUL .</p>
  <p>In my case solution is:</p>
  <pre><code>Private Sub txtcnpj_LostFocus(sender As Object, e As EventArgs) Handles txtcnpj.LostFocus
  
      If Len(txtcnpj.Text) &gt; 0 Then
  
          Select Case Len(txtcnpj.Text)
  
                        Case Is = 14
                  Dim A As String
                  A = txtcnpj.Text.Replace(&quot;.&quot;c, &quot;&quot;).Replace(&quot;/&quot;c, &quot;&quot;)
                  txtcnpj.Text = String.Concat(A.Substring(0, 2), &quot;.&quot;, A.Substring(2, 3), &quot;.&quot;, A.Substring(5, 3), &quot;/&quot;, A.Substring(8, 4), &quot;-&quot;, A.Substring(12, 2))
  
          End Select
      End If
  
  End Sub
  </code></pre>