473,404 Members | 2,179 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,404 software developers and data experts.

Splitting columns with SPACE as delimiter

Hi,

I'm working in Access and I need to split a column looking like this:

1de dok 123456 receiver

I need to convert the column to 4 new columns.

I hope someone out there can help me :)

Charlotte
Jan 8 '08 #1
2 4148
sierra7
446 Expert 256MB
Hi

You can write code to do this using the InStr() function to find the position of the first space, then slice off the first column using Left(), leaving a remaining string and repeat the operation 4 times....tedious but programmer love things like that!

I'm an engineer so it would take all day to make that work, so (especially if I only need to do it once) I would paste the column into WordPad and save it, then re-import it into Access when you can set the delimiter to a space.

I know this will put the column into a new table but it should be quite easy to manipulate in Access.

Best of luck
Jan 8 '08 #2
Minion
108 Expert 100+
First off I'll give you the code to the function I use for splitting a variety of strings into seperate segments. The best part is it has built in delimeters ( ,/!|), but you can pass it a list and override these. I always recommend doing so to make sure you only split where you want to. The return product of this will be an array, which we'll handle next.

The parsing function is as follows:

Expand|Select|Wrap|Line Numbers
  1. Public Function parse(ByVal inString, Optional ByVal delimiters)
  2. 'Take a string, and return it as a one dimensional array
  3. ' of individual values as delimited by any of several
  4. ' characters. None of those characters are returned in
  5. ' the result. Provide a default list of delimiters, which
  6. ' should come from registry. But allow override.
  7.  
  8.     Dim delimitList, oneChar, aWord, codeCount
  9.     Dim arrayCodes()
  10.  
  11.     If IsMissing(delimiters) Then
  12.         'We should get these from Registry
  13.         delimitList = " ,/!|"
  14. 'Characters recognized as delimiters
  15.  
  16.     Else
  17.         delimitList = delimiters
  18. 'user can override if needed
  19.  
  20.     End If
  21.     Dim i, j, k
  22.     i = Len(inString)
  23.     For j = 1 To i
  24. 'Read one character at a time
  25.  
  26.         oneChar = VBA.Strings.Mid(inString, j, 1)
  27.         k = InStr(delimitList, oneChar)
  28. 'Is this one a delimiter?
  29.         If k = 0 Then
  30.             aWord = aWord & oneChar
  31. 'If is isn't, add to the current word
  32.         End If
  33.         If k <> 0 Or j = i Then
  34. 'If it is, or if we're finished
  35.             If aWord > "" Then
  36.                 codeCount = codeCount + 1
  37.                 ReDim Preserve arrayCodes(codeCount)
  38.                 arrayCodes(codeCount) = aWord
  39. 'Save new word
  40.                 aWord = ""
  41.             End If
  42.         End If
  43.     Next j
  44.     parse = arrayCodes
  45. 'Return the array
  46. End Function
  47.  
To call and handle this function you'll need some code as follows:

Expand|Select|Wrap|Line Numbers
  1. Dim splitString()
  2.  
  3. splitString = parse(<<value>>," ")
  4.  
Now you have an array of your values as split by the space. By using a loop command you can send each of the values to a variable, textbox, or other location. Just in case I've included a basic loop that would send the values to series of record sets.

Expand|Select|Wrap|Line Numbers
  1. Dim j, i as Integer
  2. Dim rst as Recordset
  3.  
  4. Set rst = <<recordset definition here>>
  5.  
  6.    j = uBound(splitString)
  7.  
  8.   for i = 1 to j
  9.      rst.fields(i) = splitString(i)
  10.   next i
  11.  
Hope this helps.

- Minion -
Jan 8 '08 #3

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

Similar topics

7
by: qwweeeit | last post by:
Hi all, I am writing a script to visualize (and print) the web references hidden in the html files as: '<a href="web reference"> underlined reference</a>' Optimizing my code, I found that an...
26
by: Kai Jaensch | last post by:
Hello, i am an newbie and i have to to solve this problem as fast as i can. But at this time i don´t have a lot of success. Can anybody help me (and understand my english :-))? I have a...
8
by: Anthony Liu | last post by:
I have this simple string: mystr = 'this_NP is_VL funny_JJ' I want to split it and give me a list as 1. I tried mystr.split('_| '), but this gave me:
20
by: Opettaja | last post by:
I am new to c# and I am currently trying to make a program to retrieve Battlefield 2 game stats from the gamespy servers. I have got it so I can retrieve the data but I do not know how to cut up...
15
by: Daren | last post by:
Hi, I need to be able to split large string variables into an array of lines, each line can be no longer than 70 chars. The string variables are text, so I would additionally like the lines...
9
by: Fabian Steiner | last post by:
I often have to deal with strings like "PCI:2:3.0" or "PCI:3.4:0" and need the single numbers as tuple (2, 3, 0) or (3, 4, 0). Is there any simple way to achieve this? So far I am using regular...
1
by: cikail | last post by:
Hi there, I know there are a lot of this question in th ASP.Net section. But I'm currently in the dark. I've tried to find the answer from every search place but maybe my question was wrong. Heres...
2
by: shadow_ | last post by:
Hi i m new at C and trying to write a parser and a string class. Basicly program will read data from file and splits it into lines then lines to words. i used strtok function for splitting data to...
3
by: psbasha | last post by:
Hi , I have a string which is having tabs and space as delimiter.I would like to store the read data as list. For Example : Input: strLine = ' 12\t 13 Top\t 100' Ouput :
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.