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 and replace

Status
Not open for further replies.

hcts

Programmer
Jan 14, 2004
89
US
Hi again,

I am working with a client that is going to send their bank a .csv file with all the checks and vendor names in it. The bank says that the name field is required and CANNOT have anything other than letters in it. NO comma, period, symbol of any kind. Is there an easy way to perform a serch and remove/replace for all the symbols, puncuation marks in a text field.

Thanks in advance

James D. Howard
 
Read each character.

If alpha, store in a string variable.

When done reading, replace the field with the string variable.

Alternately, you could do a FOR loop and a match() statement, changing the string to NOT include the characters of the match().

You could also do a breakapart(), with all characters you DON'T want as part of the characters to break on. Then put the string/field back together using the items in the resulting array; the array elements will be filled with all parts that DON'T match the string you use to breakapart() on.

Tony McGuire
"It's not about having enough time. It's about priorities.
 
I have a library method that I use that does just what you want. It uses breakapart just as Tony suggested, I pass a string and paramaters into the method and it returns the string without the paramaters.

You can call it within a scan loop something like this, keep in mind that this will only work on the paramaters you enter. If your data has lots of strange characters that you need to remove you will have to compare each character in the string to the ascii table to eliminate all but alpha characters.

scan
fieldName = Strip(fieldName, ",.'")
endscan


method Strip(Str string, params string) string
var
ar array[] anytype
x number
endVar

str.breakapart(ar, params)
str.blank()
for x from 1 to ar.size()
str = str+ar[x]
endfor

return str

endMethod
 
You could potentially add all characters to the breakapart string to break on.

But I also think that a loop that checks whether each character falls within a range of acceptable characters (testing ascii value numerically) would be the easiest if you have dozens of values (characters) to get rid of.

Either way could work, though.

Tony McGuire
"It's not about having enough time. It's about priorities.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top