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

Identify Delimiters

Roy
Hi ,

I use a A2003 App.I get a text file everyday from a external source
which I use to update my tables.The problem is there is no consistent
delimiter used in this text file.Some days it is tab or other days it
uses semi-colon(;) as a delimiter.
So in my line input code I use both the codes and commenting either
one when the import fails.

Open TestFile For Input As #1
Do While Not EOF(1)
Line Input #1, str1
'str2 = Split(str1, vbTab)--the days when tab is used
str2 = Split(str1, ";"))--the days when semi-colonis used

How to identify the delimiter so that I can use a If statement to
chose one?

Thanks,

Roy

Oct 16 '07 #1
7 4975
On Oct 16, 3:45 pm, Roy <praish1...@yahoo.comwrote:
Hi ,

I use a A2003 App.I get a text file everyday from a external source
which I use to update my tables.The problem is there is no consistent
delimiter used in this text file.Some days it is tab or other days it
uses semi-colon(;) as a delimiter.
So in my line input code I use both the codes and commenting either
one when the import fails.

Open TestFile For Input As #1
Do While Not EOF(1)
Line Input #1, str1
'str2 = Split(str1, vbTab)--the days when tab is used
str2 = Split(str1, ";"))--the days when semi-colonis used

How to identify the delimiter so that I can use a If statement to
chose one?

Thanks,

Roy
You could always replace all vbTabs with semi-colons before Splitting.

Oct 16 '07 #2
Line Input #1, str1

if instr(str1,";") 0 then
str2 = Split(str1, ";"))--the days when semi-colonis used
else
str2 = Split(str1, vbTab)--the days when tab is used
end if

--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pl*****************@msn.com
Oct 17 '07 #3
On Oct 16, 4:45 pm, Roy <praish1...@yahoo.comwrote:
Hi ,

I use a A2003 App.I get a text file everyday from a external source
which I use to update my tables.The problem is there is no consistent
delimiter used in this text file.Some days it is tab or other days it
uses semi-colon(;) as a delimiter.
So in my line input code I use both the codes and commenting either
one when the import fails.

Open TestFile For Input As #1
Do While Not EOF(1)
Line Input #1, str1
'str2 = Split(str1, vbTab)--the days when tab is used
str2 = Split(str1, ";"))--the days when semi-colonis used

How to identify the delimiter so that I can use a If statement to
chose one?

Thanks,

Roy
That is a tricky problem. When the file is tab delimited, there might
be semicolons in the data and vice versa. You can blame my
mathematics background for considering such possibilities :-). You
can't just see if there are more semicolons or tabs. A reasonable
assumption might be that tabs in data are relatively rare so count the
number of tabs and use that number relative to the number of lines or
a multiple thereof (NumFields - 1) to determine what delimiter to
use. Perhaps use only the first line of data to make that decision as
Albert does (and to count the number of fields). Remember that the
success of choosing the delimiter this way is only as good as the
assumption about the number of tabs that can be in the data. OldPro's
method will fail if there are semicolons in the data. IMO, Albert's
method would be better if vbTab is checked in the 'If' rather than the
semicolon due to the assumption.

James A. Fortune
CD********@FortuneJames.com

Oct 17 '07 #4
On Oct 17, 3:36 pm, CDMAPos...@FortuneJames.com wrote:
On Oct 16, 4:45 pm, Roy <praish1...@yahoo.comwrote:


Hi ,
I use a A2003 App.I get a text file everyday from a external source
which I use to update my tables.The problem is there is no consistent
delimiter used in this text file.Some days it is tab or other days it
uses semi-colon(;) as a delimiter.
So in my line input code I use both the codes and commenting either
one when the import fails.
Open TestFile For Input As #1
Do While Not EOF(1)
Line Input #1, str1
'str2 = Split(str1, vbTab)--the days when tab is used
str2 = Split(str1, ";"))--the days when semi-colonis used
How to identify the delimiter so that I can use a If statement to
chose one?
Thanks,
Roy

That is a tricky problem. When the file is tab delimited, there might
be semicolons in the data and vice versa. You can blame my
mathematics background for considering such possibilities :-). You
can't just see if there are more semicolons or tabs. A reasonable
assumption might be that tabs in data are relatively rare so count the
number of tabs and use that number relative to the number of lines or
a multiple thereof (NumFields - 1) to determine what delimiter to
use. Perhaps use only the first line of data to make that decision as
Albert does (and to count the number of fields). Remember that the
success of choosing the delimiter this way is only as good as the
assumption about the number of tabs that can be in the data. OldPro's
method will fail if there are semicolons in the data. IMO, Albert's
method would be better if vbTab is checked in the 'If' rather than the
semicolon due to the assumption.

James A. Fortune
CDMAPos...@FortuneJames.com- Hide quoted text -

- Show quoted text -
Of course, if there are semi-colons in the data of a text file
delimited by semi-colons, then it won't work anyway. Whatever the
data is, one would hope that there are no tabs or semi-colons!

Oct 18 '07 #5
On Oct 18, 11:51 am, OldPro <rrossk...@sbcglobal.netwrote:
Of course, if there are semi-colons in the data of a text file
delimited by semi-colons, then it won't work anyway. Whatever the
data is, one would hope that there are no tabs or semi-colons
An even better idea might be to parse the first data line until the
first of either two tabs or two semi-colons are encountered. That
should cut down the odd cases to almost nothing. Data delimited by
tabs may contain semi-colons. You can't ignore that possibility
because you don't know the delimiter a priori.

James A. Fortune
CD********@FortuneJames.com

Oct 19 '07 #6

Will the file *always* have a known number of "fields" in it?

If so, use the split function to find out if it has the right amount
of fields. Try it once with vbTab, then (if that returns the wrong
number of fields) try the semi-colon.

Public Function CountFields(strIn As String, _
strDelimiter As String) _
As Long
Dim varFields As Variant

varFields = Split(strIn, strDelimiter)
CountFields = UBound(varFields)
End Function

On Tue, 16 Oct 2007 13:45:36 -0700, Roy <pr********@yahoo.comwrote:
>I use a A2003 App.I get a text file everyday from a external source
which I use to update my tables.The problem is there is no consistent
delimiter used in this text file.Some days it is tab or other days it
uses semi-colon(;) as a delimiter.
So in my line input code I use both the codes and commenting either
one when the import fails.

Open TestFile For Input As #1
Do While Not EOF(1)
Line Input #1, str1
'str2 = Split(str1, vbTab)--the days when tab is used
str2 = Split(str1, ";"))--the days when semi-colonis used

How to identify the delimiter so that I can use a If statement to
chose one?
Please Post Any Replies To This Message Back To the Newsgroup.
There are "Lurkers" around who can benefit by our exchange!
Oct 19 '07 #7
On Oct 19, 7:29 pm, Chuck Grimsby <c.grim...@worldnet.att.net.invalid>
wrote:
Will the file *always* have a known number of "fields" in it?

If so, use the split function to find out if it has the right amount
of fields. Try it once with vbTab, then (if that returns the wrong
number of fields) try the semi-colon.

Public Function CountFields(strIn As String, _
strDelimiter As String) _
As Long
Dim varFields As Variant

varFields = Split(strIn, strDelimiter)
CountFields = UBound(varFields)
End Function
That's a good idea. If you can enforce that the field names be
included on the first line it gets even simpler since they should be
flogged if they use a tab or a semi-colon as part of a field name.

James A. Fortune
CD********@FortuneJames.com

Oct 21 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Markus Elfring | last post by:
Hello, I try to use alternative delimiters for a regular expression. When will it be supported? www@mike:/home/www > /usr/local/bin/php -a Interactive mode enabled <?php...
3
by: Justin L. Kennedy | last post by:
I am looking for a function that takes in a string and splits it using a list of other strings (delimiters) and can return the delimiters as well as the extra parts of the string. I was trying the...
10
by: John | last post by:
Ok, I posted in here a few days ago about a problem with apostrophes in text fields and I tried a few of the suggestions and now I'm in so deep I looking at scraping the whole thing because now I...
2
by: Bill Moran | last post by:
I'm having some problems using \copy I have a directory full of test data that I want to be installed automatically when "make database" is issued. While the Makefile rules would seem simple,...
6
m6s
by: m6s | last post by:
1. After hours of researching, I used these snippets : void Object::TokenizeLines(const string& str, vector<string>& tokens, const string& delimiters) // Skip delimiters at beginning....
4
by: bearophileHUGS | last post by:
This is the best praise of semantic indentation I have read so far, by Chris Okasaki: http://okasaki.blogspot.com/2008/02/in-praise-of-mandatory-indentation-for.html A quotation: I have...
1
by: zeny | last post by:
Hey folks! Can anyone tell me how to add data to a table using "copy" with several delimiters? Is it possible? What i mean is: Copy <table_name> from <file_directory> using delimiters...
5
by: gpaps87 | last post by:
hi, i wanted to know whether we can use strtok command to mark delimiters as tokens as well.In Java,we have a command: StringTokennizer(String str, String delimiters, boolean delimAsToken) ...
4
by: Marco Trapanese | last post by:
Hi, I'm trying to parse strings on an Atmel AVR device. I use the WinAVR C Compiler (GCC) The strings to parse are like this: command -par0 -par1 -parn I use strok_r function:
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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.