473,324 Members | 1,646 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

How to remove spaces in text fields

I'm extracting data from a database to create a table.

My table includes a text field 'Postcode' for postcodes.

Sometimes the extracted postcodes are in the format SL37HY and in other
instances a gap has been left somewhere in the data e.g. S L37HY or
SL3 7HY.

I want to validate the postcodes by matching them to a master table which
contains postcodes in the format SL37HY i.e. no spaces.

So......any advice....I need a simple way to edit my table and remove spaces from entries in the field 'Postcode' ??

Thanks in advance
May 3 '07 #1
3 4800
cyberdwarf
218 Expert 100+
Hi John

I would normally use an array of characters, basic idea being:-
  1. Loop thru the array looking for space character
  2. If found, save the array index where the space was found
  3. loop thru the remaining elements, moving them up one index
  4. Starting at the index you saved, loop thru the array looking for space character
  5. Go to 2
Of course you could also use a string and the Mid function, but you then have to get chunks of the string up to the Len of the string, which will change once a space is found

HTH
Steve
May 3 '07 #2
Lysander
344 Expert 100+
Hi John

I would normally use an array of characters, basic idea being:-
  1. Loop thru the array looking for space character
  2. If found, save the array index where the space was found
  3. loop thru the remaining elements, moving them up one index
  4. Starting at the index you saved, loop thru the array looking for space character
  5. Go to 2
Of course you could also use a string and the Mid function, but you then have to get chunks of the string up to the Len of the string, which will change once a space is found

HTH
Steve
This worked for me in the intermediate window
?replace("N13 4EH"," ","")
gave
N134EH

i.e. replace all spaces with nothing.
May 3 '07 #3
NeoPa
32,556 Expert Mod 16PB
This worked for me in the intermediate window
Expand|Select|Wrap|Line Numbers
  1. ?Replace("N13 4EH"," ","")
gave
N134EH

i.e. Replace all spaces with nothing.
Lysander got my (therefore the best :D) answer in before me.

I find this one of the functions I use the most in my code (along with Nz() & IIf()).
May 5 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: p s | last post by:
hi all i have a vb6 project, one of the functions is to read in a text file and place it into an array problem is, when people use the TAB key in the original file that is read, i just get the...
4
by: Purdy | last post by:
I have an asp.net application. i export to excel, in exporting to excel i use an xslt to define the columns and look. on one of the fields i need the word 'qty' but i need it to look like ' ...
3
by: SKG | last post by:
i have leading spaces in my database fields. When they appear in the datagrid in browser, they seem to be truncated. I did view source in browser and found that there are indeed spaces but when...
7
by: usenet | last post by:
I would like, if it's possible, to set the value of a field in a table to a number of spaces. One space would be fine, I just want to be able to set the field to a default value that's not NULL...
17
by: tommy | last post by:
Hi all, I' m adding strings to some fields in my table via Access. The strings sometimes have trailing spaces and I really need to have it that way, but Access truncates trailing spaces. How can...
7
by: Mike Johnson | last post by:
How do I remove a item that's been selected from a listview? I'm using Visual Basic 2005 express edition. Thanks
1
by: andrewbda | last post by:
I am having a problem where fields are being filled by spaces when data is put in. I.e. in a text field length 50, whatever is stored in there is padded by spaces and the field length is always...
1
by: buggtb | last post by:
Hi Guys, I've been given the joyous task of updating some very old scripts at work and I could do with a little help. Our Unix system dumps text files to pseudo spoolers that our windows...
1
by: maryanncanor | last post by:
Hi everyone, My problem is whenever I export a report to a textfile. The output textfile have blank spaces. Here is my query: SELECT ( & '|' & & '|'...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.