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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validate and convert a string prior to exporting

Status
Not open for further replies.

xpower

MIS
Oct 21, 2003
3
0
0
GB
I am attempting to create a text file based on a table within my database.
One field is a text field, max 30 characters, that contains special characters (e.g. /],+.}_) in addition to text. I need to remove these special characters prior to exporting the data
e.g.
HELLO./WORLD]} needs converting to
HELLO WORLD or HELLO WORLD
The table is refreshed often from external souce so this is not a 'one-off' task, and conversion must take place on exporting the data (not when importing).

Thanks in advance for any assistance.
 
have a look at an ascii table. If it is only upper case and lower case characters you want to keep, you could try the following treatment on your string;

For i = 1 to 31
strString = Replace(strString, Chr(i), "")
Next i

For i = 33 to 64
strString = Replace(strString, Chr(i), "")
Next i

For i = 91 to 96
strString = Replace(strString, Chr(i), "")
Next i

For i = 123 to 255
strString = Replace(strString, Chr(i), "")
Next i

There's probably a more elegant way to do this, but this is the first thing that came to mind. This replaces everything with nothing with the exception of characters and the space (#32).

good luck!
 
Dim Str1 as String, Str2 as String
Dim i as Integer
...
for i=1 to len(Str1)
If Mid(Str1, i, 1) >= 65 And Mid(Str1, i, 1) <= 90 Or Mid(Str1, i, 1) >= 97 And Mid(Str1, i, 1) <= 127 Then
Str2 = Str2 & Mid(Str1, i, 1)
Else
Str2 = Str2 & &quot; &quot;
End If
Next i
...
Trim (Str2)

If you export Str2 now, all unnecessary characters will be converted to spaces.
:)
MakeItSo

Andreas Galambos
EDP / Technical Support Specialist
(andreas.galambos@bowneglobal.de)
HP:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top