Listbox total replaced

Hi,

I am trying to replace on a string,

dim i as integer
for i = 0 to Listbox1.RowCount -1
  Listbox1.cell(i,1)=ReplaceAll(Listbox1.cell(i,1), "(D)", "")
  Listbox1.cell(i,1)=ReplaceAll(Listbox1.cell(i,1), " (D)", "")
  Listbox1.cell(i,1)=ReplaceAll(Listbox1.cell(i,1), " (D) (D)", "")
  Listbox1.cell(i,1)=ReplaceAll(Listbox1.cell(i,1), "*", "") 
  Listbox1.cell(i,1)=ReplaceAll(Listbox1.cell(i,1), " *", "")
  Listbox1.cell(i,1)=ReplaceAll(Listbox1.cell(i,1), " * *", "")
  Listbox1.cell(i,1)=ReplaceAll(Listbox1.cell(i,1), " (grabmart)", "")
  Listbox1.cell(i,1)=ReplaceAll(Listbox1.cell(i,1), "(grabmart)", "")
  Listbox1.cell(i,1)=ReplaceAll(Listbox1.cell(i,1), " (two Side)", "")
  Listbox1.cell(i,1)=ReplaceAll(Listbox1.cell(i,1), ".", "")
next

this is works, but is there anyway to get the result how many strings have been replaced by each criteria.
The string in listbox has the sign/text randomly.

any helps,

thanks
arief

In many loops, use Replace() instead of ReplaceAll and count the loop iteration.

The string in listbox has the sign/text randomly.
This I do not understand, sorry.

Hi,
this i mean the criteria that I have define, like '*" ‘(D)’, ‘(grabmart)’ etc. The listbox row, some of the string has this. I want to remove/replace it.

basically I want to know if there are some string have been replaced.
I dont know how to count it.

thanks
arief

Replace the values in a loop and count them.
Not tested:

Var replacements() As String = Array("(D)", " (D)", " (D) (D)", "*", " *", " * *", " (grabmart)", "(grambart)", " (two Side)", ".")
Var replacementCnt As Integer

For i As Integer = 0 To ListBox1.LastRowIndex
  
  Var cellText As String = ListBox1.CellTextAt(i, 1)
  
  For Each replacement As String In replacements
    
    While cellText.IndexOf(replacement) > -1
      
      replacementCnt = replacementCnt + 1
      cellText = cellText.Replace(replacement, "")
      
    Wend
    
  Next
  
  ListBox1.CellTextAt(i, 1) = cellText
  
Next

Hi,
this is work. but how to find the total of string that have been replace in integer value.

I add this code, but the result is 0

MessageBox str(replacementCnt)

thanks
arief

If this is so, then no replacements were made.
Are you sure you want to replace the values in column 1?
Not in column 0 (index 0 is the first column)?

I just want to count.
Counting the listbox.rowcount did the tricks.

thanks for all the helps.

regards,
arief