Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search for Characters in all data in table

Status
Not open for further replies.

nallen

IS-IT--Management
Oct 20, 2003
10
US
Does anyone know an easy way to search for a specific set of characters (%, \, <) in an entire table? For example, I need to see if the &quot;%&quot; character is anywhere in the data in table &quot;mytable&quot; and then replace it with whitespace if it is.

Thanks,

Nicole
 
Use MyTable
cChar = '%' && or whatever Char you're looking for.
nChar = '' && New Character, in this case.. Blank
For x = 1 to Fcount() && all the fields.
if vartype(Field(x)) && make sure it is a char field.
Replace all Field(x) with StrTran(Evalute(Field(x)),cChar,nChar)
endif
endfor



Ali Koumaiha
TeknoSoft Inc
Farmington Hills, Michigan
 
^^ Correction Above.

The line: IF Vartype(field(x))

Should Read: If VarType(Field(x)) == 'C' && for Character

Ali Koumaiha
TeknoSoft Inc
Farmington Hills, Michigan
 
^^ Another Correction (Sorry, Sloppy writing without double checking it) :)

The line:

Replace All Field(x) with StrTran....

Should Read:

Replace All (Field(x)) with ....



Ali Koumaiha
TeknoSoft Inc
Farmington Hills, Michigan
 
Great,Thanks! But is there a way I can check for all specified characters (not just one at a time) as I traverse the fields in the table?

cChar = '%' OR '#' OR &quot;\&quot;

??
 
cChar1 = '%'
cChar2 = '#'
cChar3 = '\'

In the code above:

if cChar1 $ Evaluate(field(x)) && '%' is here
Do the StrTran thing
endif
if cChar2 $ Evaluate(field(x)) && '#' is here.

etc..
etc..

Ali Koumaiha
TeknoSoft Inc
Farmington Hills, Michigan
 
Other handy functions for find characters, positing, etc. are:

? Occurs(&quot;%&quot;,fieldname)
? ATC(&quot;%&quot;,fieldname)

Using these you can implement an i = 1 to occurances if you need to do some special handling and not just a replace of a character.

Jim Osieczonek
Delta Business Group, LLC
 
cChar = &quot;%?&><()#@' && list of characters
nChar = SPACE(1) && New Character as Blank
OR
nChar = &quot;&quot; && Just nothing if you want to eliminate

FOR y = 1 TO LEN(cChar)
cStr = SUBSTR(cChar,y,1)
FOR x = 1 TO FCOUNT()
IF VARTYPE(EVALUATE(FIELD(x))) $ &quot;CM&quot;
REPLACE ALL (FIELD(x)) WITH ;
CHRTRAN(EVALUATE(FIELD(x)),cChar,nChar)
ENDIF
ENDFOR
ENDFOR

:)

ramani :)
(Subramanian.G)
 
Hi

Ignore the previous post and use the following code.
*******************************************
cChar = &quot;%?&><()#@' && or whatever you want to replace
nChar = SPACE(1) && New Character as replacement
OR
nChar = &quot;&quot; && Just nothing if you want to eliminate

FOR y = 1 TO LEN(cChar)
cStr = SUBSTR(cChar,y,1)
FOR x = 1 TO FCOUNT()
IF VARTYPE(EVALUATE(FIELD(x))) $ &quot;CM&quot;
REPLACE ALL (FIELD(x)) WITH ;
CHRTRAN(EVALUATE(FIELD(x)),cStr,nChar)
ENDIF
ENDFOR
ENDFOR
****************************************
:)

ramani :)
(Subramanian.G)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top