Subject Re: find and delete within one field
From Mervyn Bick <invalid@invalid.invald>
Date Sun, 10 Mar 2019 22:33:05 +0200
Newsgroups dbase.getting-started
Attachment(s) remove_commas.prg

On 2019-03-10 9:02 PM, Charlie wrote:
> Hi... I would like to find all comma's in a particular field and delete them.   How can this be done?
>

A little example is attached.

Mervyn.





if file('remove_commas.dbf')
drop table remove_commas
endif

if not file('remove_commas.dbf')
   create table remove_commas  (id autoinc,data character(35))
   insert into remove_commas  (data) values ("dsf, gfghfh,  erertet, ertert")
   insert into remove_commas  (data) values ("ertert, ererert, rtyry,erer, fghfgh")
   insert into remove_commas  (data) values ("qweqwe, wwerwer ,,,werwre, ertet")
endif
clear
use remove_commas
list off all
use
?
q = new query()
q.sql = 'select * from remove_commas'
q.active = true
do while not q.rowset.endofset
  q.rowset.fields['data'].value = remove_commas(q.rowset.fields['data'].value)
  q.rowset.next()
enddo
q.active = false
use remove_commas
list off all
use

Function remove_commas(cStr)
   do while ','$cStr
      cStr = stuff(cStr,at(',',cStr),1,'')
   enddo
   return cStr