title: how to replace lastindexof "," to the word "and" but avoid to replace "and" inside the open and close parenthesis in vb.net
body: <p>how to replace last accurancy "," to the word "and" but avoid to replace "and" inside the open and close parenthesis in vb.net</p>
  
  <p>sample:</p>
  
  <p>A,A1,A2,A3,B,B1,B2,B3,C,C1,C2,C3</p>
  
  <p>i want the output like this
  A(A1,A2,A3),B(B1,B2,B3) and C(C1,C2,C3)</p>
  
  <p>this is my code:
   Dim Strng As String = Me.CheckBox1.Text</p>
  
  <pre><code>    'now find the position of last appearing ","
      Dim comaposition As Integer
      comaposition = Strng.LastIndexOf(",") 'it is zero  based
  
      'if not found, it will return -1 and u can exit, no need to do the work
      If comaposition = "-1" Then
  
          Exit Sub
      End If
  
      'remove the comma
      Dim String_After_Removing_Comma As String
      String_After_Removing_Comma = Strng.Remove(comaposition, 1)
  
      'add "and" in the same position where comma was found
      Dim final_string As String
      final_string = String_After_Removing_Comma.Insert(comaposition, " and ")
  
      'show it on the textbox
      CheckBox1.Text = final_string
  </code></pre>
  
  <p>how can i do that any idea</p>