Removing All Spaces Between Data In Text Field ? (1 Viewer)

The Brown Growler

Registered User.
Local time
Today, 06:34
Joined
May 24, 2008
Messages
85
Hi,

Would anyone please be able to help me with a query to remove all spaces between data stored in a text field?

For example:
08 CG 52 should convert to 08CG52
07 FR SR 56 should convert to 07FRSR56

Ther is no uniformity to the data, ie, there could be 2, 3, 4 or more blocks of info in the field and I need to remove all spaces and any other invisible non printing characters etc.

I have tried TRIM but it leaves the in between spaces. If there is a custom public function that I could use in the query grid then that would be ideal.

Thx & Regards
Growler
 

stopher

AWF VIP
Local time
Today, 06:34
Joined
Feb 1, 2006
Messages
2,395
Take a look at the REPLACE function.
e.g. the following will replace all spaces with an empyt string
Code:
REPLACE([myString]," ","")


hth
Chris
 

raskew

AWF VIP
Local time
Today, 00:34
Joined
Jun 2, 2001
Messages
2,734
Hi -

I've modified a function originally written in A97 (no Replace() function) to remove excess spaces. Copy/paste to a standard module and call as shown in the example.

Code:
Function NoSpace(pstr As String) As String

'*******************************************
'Purpose:   Removes all spaces from a string
'Coded by:  raskew
'Input:     ? nospace("07 FR SR 56")
'Output:    "07FRSR56"
'*******************************************

Dim strHold As String
    strHold = RTrim(pstr)
    Do While InStr(strHold, " ") > 0
      strHold = Left(strHold, InStr(strHold, " ") - 1) & Mid(strHold, InStr(strHold, " ") + 1)
    Loop
    NoSpace = Trim(strHold)
    
End Function

HTH - Bob
 

raskew

AWF VIP
Local time
Today, 00:34
Joined
Jun 2, 2001
Messages
2,734
Chris -

Obviously I needed to study-up on the Replace() function. Just realized it, by default, replaces all instances of the specified value. Duh!

My solution, although it works, is totally cumbersome by comparison.

Best Wishes - Bob
 

stopher

AWF VIP
Local time
Today, 06:34
Joined
Feb 1, 2006
Messages
2,395
Obviously I needed to study-up on the Replace() function. Just realized it, by default, replaces all instances of the specified value. Duh!

My solution, although it works, is totally cumbersome by comparison.
Don't worry Bob. I only recently picked up on it when Lagbolt posted that incredibly short code. I think you also wrote a nice bit of code if I remember rightly.

Chris
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 06:34
Joined
Sep 12, 2006
Messages
15,660
i have the same problem

I am so used to A97, I tend to not use later functions like

replace, instrrev, and split

and use workrounds for them, when they are needed - there are probably loads of other functions that appeared after A97 as well
 

raskew

AWF VIP
Local time
Today, 00:34
Joined
Jun 2, 2001
Messages
2,734
Brent -

Suspect that most of us A97 'dinosaurs' probably have a similar set of workarounds. Just went back and checked and found similar workarounds for all of the functions listed in your article.

Best Wishes - Bob
 

datAdrenaline

AWF VIP
Local time
Today, 00:34
Joined
Jun 23, 2008
Messages
697
Hey Bob ...

Yep, I had a couple (InStrREV and Replace) .. but then I found that article and just pulled them all into my A97 apps and discarded all mine for those found in the article....

BTW: the article is not mine ... it sorta sounded like you thought is was, so I thought I would clarify that! ... :)
 

Users who are viewing this thread

Top Bottom