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

Parsing out ( and ) characters 2

Status
Not open for further replies.

John1Chr

Technical User
Sep 24, 2005
218
US
I don’t think this will be too difficult. I want to take out the( and )from some of the numbers that are in a field. Most of the records do not have the( and ) in them. There is always four characters in front of the dash. Within the parentheses the record might have a letter in it. In addition, the number of characters in the field varies. Examples are below:

2604-(26X03) should be 2604-26X03
4610-(96719) should be 4610-96719
5618-(5025) should be 5618-5025
2103-(95108) should be 2103-95108
5622-12 should be 5622-12 (unchanged)
5628-3 should be 5628-3 (unchanged)
4402-881 should be 4402-881 (unchanged)
 
Code:
Replace(Replace(TheString,"(",""),")","")
 
Hi BrGenCaj! Why not keep it simple and use
Code:
[b]First Time:[/b]
Edit>Replace
Find What [!]([/!]
Replace With
Look In: [!]YourField[/!]
Match: [!]Any Part of Field[/!]

Then run it again:
Code:
[b]Second Time:[/b]
Edit>Replace
Find What [!])[/!]
Replace With
Look In: [!]YourField[/!]
Match: [!]Any Part of Field[/!]

If it is really necessary, you could write a VB procedure for this and make it a permanenet feature in your db, but for now the thing to determine is whether or not you really need that functionality or if a simple built in tool will do the job.

Hope this helps.

Tom

Born once die twice; born twice die once.
 
Forgive me if I seem naïve, were you two thinking of having this set up as a function? Let’s say the field name is plop and it is in table name toilet. How would you write the total code? (Often, I feel like I am at an entry level with VB so if you feel like you are spoon feeding me you might be correct.)
 
I just gave you a function (Replace) that you can use in VBA or SQL.

In VBA
Code:
TheString = "2604-(26X03)"
TheString = Replace(Replace(TheString,"(",""),")","")
[COLOR=black cyan]' Produces 2604-26X03 in TheString[/color]

In SQL
Code:
UPDATE myTable 
SET TheField = Replace(Replace(TheField,"(",""),")","")
Where InStr(TheField,"(") > 0
   OR InStr(TheField,")") > 0
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top