• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1187
  • Last Modified:

Strip comma, tabs, carriage returns, tabs etc from text field

I have a ver large database that I need to export to a tab delimited file for import into another system.  The problem I have is there is a note field, and others, that have commas, tabs, quotes, tabs, carraige returns etc. in it.  naturally this reaks havoc on a tab delimited file.

Is there a way to query or code against these fields to either remove them or replace them?
0
keschuster
Asked:
keschuster
  • 4
  • 3
  • 3
  • +1
1 Solution
 
LennyGrayCommented:
It appears that you only need to edit-out the tabs within the data elements of the table. The problem is that the tabs are your only problem. So, simply do a search and replace in each data column that contains tabs and replace the tabs with some other special character. You can then replace the special character with the tab after the export.
0
 
keschusterAuthor Commented:
I've figured this much out
UPDATE Parcel SET Parcel.[Property Name] = Replace([Property Name],Chr(13),"|")
checks for one character and replaces.  there are 4 characters I need to check for across 4 or more fields.

Instead of running 4 queries against each of the 4 fields I'd like to code tthis into a function that I could have update all of these characters via a call from one query.
0
 
Mike EghtebasDatabase and Application DeveloperCommented:
Would you want to use | instead of tab to seperate your fields.

| is not a very common character and it is located on the same key as \.

| looks like I o l but it is neither.

Mike
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
keschusterAuthor Commented:
normally I would but tab is a requirment
0
 
Mike EghtebasDatabase and Application DeveloperCommented:
Add |

Replace all unwanted ones

Replace | with tabs.
0
 
Mike EghtebasDatabase and Application DeveloperCommented:
sorry, I didn't read your post fully. You already had | in mind.
0
 
rockiroadsCommented:
Hi Mike :)

kes, I have a vba func which you could use. It is used to strip out the crap that you dont want

Public Function GetRidOfThoseNastyChars(sMemoText As String) As String

    Dim sReturn As String
    Dim x
   
    sReturn = ""
    For x = 1 To Len(sMemoText)
        If (Asc(Mid(sMemoText, x, 1)) >= 48 And Asc(Mid(sMemoText, x, 1)) < 57) Or _
        (Asc(Mid(sMemoText, x, 1)) >= 97 And Asc(Mid(sMemoText, x, 1)) < 122) Or _
        (Asc(Mid(sMemoText, x, 1)) >= 65 And Asc(Mid(sMemoText, x, 1)) < 90) Then
            sReturn = sReturn & Mid(sMemoText, x, 1)
        End If
    Next
   
    GetRidOfThoseNastyChars = sReturn

End Function



Now you can use this in a query eg

update mytable set myfield = GetRidOfThoseNastyChars(myfield)

0
 
rockiroadsCommented:
Simple solution, basically iterate thru each char in the specified string and build up a new string by accepting those 0-9, a-z or A-Z ranges only.
0
 
keschusterAuthor Commented:
That looks about what I was thinking.  How do you think this will perfom on 80k records with each record having 4 columns to be evaluated.
0
 
rockiroadsCommented:
Well only one way to find out

My personal choice would be to create the whole code in vba. Create a recordset and iterate thru that.
0
 
LennyGrayCommented:
you did not allow for spaces (Ascii 20)
0
 
keschusterAuthor Commented:
I ran the code and the speed was just fine.  I do want to modify to look for specific characters and replace them with a space.  But this is the right way to go
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

  • 4
  • 3
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now