473,387 Members | 1,541 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,387 software developers and data experts.

remove space at end of text file

JT
i have written some asp that reads a fixed length text file, line by line,
inserting each line into my database. my problem is that the text file
format seems to have extra space at the end of the file so my code thinks
there is actually one more line when there is not. is there a way to remove
these spaces before i loop through the file?

here is my sample code:

Do While df.AtEndOfStream <> True
line = df.ReadLine

account_no = trim(mid(line,3,9))
account_no = cleansedata(account_no, 1)

customer_name = trim(mid(line,12,28))
customer_name = cleansedata(customer_name, 1)

etc., etc.

Loop
Jul 19 '05 #1
8 2805
Do While df.AtEndOfStream <> True
line = df.ReadLine

If Not line = "" Then
account_no = trim(mid(line,3,9))
account_no = cleansedata(account_no, 1)
customer_name = trim(mid(line,12,28))
customer_name = cleansedata(customer_name, 1)
etc., etc.
End If
Loop

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

Disclaimer:
I know I'm probably wrong, I just like taking part ;o)
JT <je******@sppinc.net> wrote in message
news:O$*************@tk2msftngp13.phx.gbl...
i have written some asp that reads a fixed length text file, line by line,
inserting each line into my database. my problem is that the text file
format seems to have extra space at the end of the file so my code thinks
there is actually one more line when there is not. is there a way to remove these spaces before i loop through the file?

here is my sample code:

Do While df.AtEndOfStream <> True
line = df.ReadLine

account_no = trim(mid(line,3,9))
account_no = cleansedata(account_no, 1)

customer_name = trim(mid(line,12,28))
customer_name = cleansedata(customer_name, 1)

etc., etc.

Loop

Jul 19 '05 #2
Instead of looping through the stream and keeping a handle on the file
throughout, how about:

set fso = CreateObject("Scripting.FileSystemObject")
set fs = fso.openTextFile("path:\filename.ext", 1)
blob = fs.ReadAll()
fs.close: set fs = nothing: set fso = nothing

lines = split(blob, vbCrLf)
for i = 0 to ubound(lines)
thisline = trim(lines(i))
if thisline <> "" then
' execute SQL statement to insert the line
else
' this was en empty line
end if
next
An article on other things FSO-related:
http://www.aspfaq.com/2039

You didn't mention what database you were using, but if it's SQL Server, you
can use BULK INSERT (which allows you to skip n lines, ignore a user-defined
number of "problem" rows, etc.) or BCP, as a better alternative to having
ASP do this work...

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/


"JT" <je******@sppinc.net> wrote in message
news:O$*************@tk2msftngp13.phx.gbl...
i have written some asp that reads a fixed length text file, line by line,
inserting each line into my database. my problem is that the text file
format seems to have extra space at the end of the file so my code thinks
there is actually one more line when there is not. is there a way to remove these spaces before i loop through the file?

here is my sample code:

Do While df.AtEndOfStream <> True
line = df.ReadLine

account_no = trim(mid(line,3,9))
account_no = cleansedata(account_no, 1)

customer_name = trim(mid(line,12,28))
customer_name = cleansedata(customer_name, 1)

etc., etc.

Loop

Jul 19 '05 #3
> If Not line = "" Then

Careful, if there's an empty space there, this will fail...

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
Jul 19 '05 #4
JT
i am using sql server - what's this about bulk insert???
"Aaron Bertrand [MVP]" <aa***@TRASHaspfaq.com> wrote in message
news:Ow*************@TK2MSFTNGP12.phx.gbl...
Instead of looping through the stream and keeping a handle on the file
throughout, how about:

set fso = CreateObject("Scripting.FileSystemObject")
set fs = fso.openTextFile("path:\filename.ext", 1)
blob = fs.ReadAll()
fs.close: set fs = nothing: set fso = nothing

lines = split(blob, vbCrLf)
for i = 0 to ubound(lines)
thisline = trim(lines(i))
if thisline <> "" then
' execute SQL statement to insert the line
else
' this was en empty line
end if
next
An article on other things FSO-related:
http://www.aspfaq.com/2039

You didn't mention what database you were using, but if it's SQL Server, you can use BULK INSERT (which allows you to skip n lines, ignore a user-defined number of "problem" rows, etc.) or BCP, as a better alternative to having
ASP do this work...

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/


"JT" <je******@sppinc.net> wrote in message
news:O$*************@tk2msftngp13.phx.gbl...
i have written some asp that reads a fixed length text file, line by line, inserting each line into my database. my problem is that the text file
format seems to have extra space at the end of the file so my code thinks there is actually one more line when there is not. is there a way to

remove
these spaces before i loop through the file?

here is my sample code:

Do While df.AtEndOfStream <> True
line = df.ReadLine

account_no = trim(mid(line,3,9))
account_no = cleansedata(account_no, 1)

customer_name = trim(mid(line,12,28))
customer_name = cleansedata(customer_name, 1)

etc., etc.

Loop


Jul 19 '05 #5
Here's one sample.
http://www.sqlteam.com/item.asp?ItemID=3207

Ray at work

"JT" <je******@sppinc.net> wrote in message
news:eK**************@tk2msftngp13.phx.gbl...
i am using sql server - what's this about bulk insert???
"Aaron Bertrand [MVP]" <aa***@TRASHaspfaq.com> wrote in message
news:Ow*************@TK2MSFTNGP12.phx.gbl...
Instead of looping through the stream and keeping a handle on the file
throughout, how about:

set fso = CreateObject("Scripting.FileSystemObject")
set fs = fso.openTextFile("path:\filename.ext", 1)
blob = fs.ReadAll()
fs.close: set fs = nothing: set fso = nothing

lines = split(blob, vbCrLf)
for i = 0 to ubound(lines)
thisline = trim(lines(i))
if thisline <> "" then
' execute SQL statement to insert the line
else
' this was en empty line
end if
next
An article on other things FSO-related:
http://www.aspfaq.com/2039

You didn't mention what database you were using, but if it's SQL Server,

you
can use BULK INSERT (which allows you to skip n lines, ignore a

user-defined
number of "problem" rows, etc.) or BCP, as a better alternative to having
ASP do this work...

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/


"JT" <je******@sppinc.net> wrote in message
news:O$*************@tk2msftngp13.phx.gbl...
i have written some asp that reads a fixed length text file, line by

line, inserting each line into my database. my problem is that the text file format seems to have extra space at the end of the file so my code thinks there is actually one more line when there is not. is there a way to

remove
these spaces before i loop through the file?

here is my sample code:

Do While df.AtEndOfStream <> True
line = df.ReadLine

account_no = trim(mid(line,3,9))
account_no = cleansedata(account_no, 1)

customer_name = trim(mid(line,12,28))
customer_name = cleansedata(customer_name, 1)

etc., etc.

Loop



Jul 19 '05 #6
"JT" <je******@sppinc.net> wrote in message
news:eK**************@tk2msftngp13.phx.gbl...
i am using sql server - what's this about bulk insert???


http://msdn.microsoft.com/library/en...t_bcp_2e5s.asp

This information is also available in BOL (Books Online).
Jul 19 '05 #7
> i am using sql server - what's this about bulk insert???

Well, the command is called BULK INSERT, and it's a *very* fast way to
insert big log files or other plain text formats into a table. The format
is basically this:

BULK INSERT <tablename>
FROM '<path to file>'
WITH
(
ROWTERMINATOR = '\n',
FIELDTERMINATOR = '\t', -- for TSV, or ',' for CSV
MAXERRORS = 10,
FIRSTROW = 3,
ORDER (<usually_clust_index_col_name(s)>)
)

You should play with it, it's very powerful. See http://www.aspfaq.com/2438
for a couple of examples, and an explanation of some of the parameters.
You can read much more about BULK INSERT, and also BCP (which stands for
bulk copy) in Books Online. If you're not familiar with Books Online, see
http://www.aspfaq.com/2229

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
Jul 19 '05 #8
I would normally have used Len instead of "" but wasn't sure if ASP
supported it or not.

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

Disclaimer:
I know I'm probably wrong, I just like taking part ;o)
Aaron Bertrand [MVP] <aa***@TRASHaspfaq.com> wrote in message
news:uK**************@TK2MSFTNGP11.phx.gbl...
If Not line = "" Then


Careful, if there's an empty space there, this will fail...

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/

Jul 19 '05 #9

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

Similar topics

8
by: Joseph | last post by:
I have a textBox that people writes stories in it. They can use for format. I have Aspell installed on the server, so people can make correction to their text. Sometimes, they forget to add a...
18
by: prasanna.hariharan | last post by:
Hi guys, I want to remove certain words from a c++ string. The list of words are in a file with each word in a new line. I tried using the std::transform, but it dint work. Anybody got a clue...
3
by: Mark | last post by:
I need to remove a square character from a text file. How can I locate a square character and remove it? Thanks. Mark
3
by: Paul | last post by:
Hi, My RichTextBox has multiple lines of text. Most of the lines unfortunately end with a space. Is it possible to replace the space and NewLine/Line Feed with just the NewLine/LineFeed? So...
4
by: sherifffruitfly | last post by:
Hi all, I've got a csv file for numeric data, some of which are greater than 10^3. Some bright fellow trying to br helpful put US-standard commas in these numbers, and to maintain the correct...
12
by: snow | last post by:
Hi All, I noticed if file path has a white space, for example "C:\my document \test.txt", the function File.Exists(filePath) always return false in release mode. How could I make this function...
3
by: afr02hrs | last post by:
Hi Experts I am trying to get the following program running correctly. I would like to be able to input a line of text containing multiple space characters between words and have the program...
6
by: Romulo NF | last post by:
Greetings again to everyone, Im back to show this grid componenet i´ve developed. With this grid you can show the data like a normal table, remove the rows that you need, add rows, import data,...
4
by: lilly07 | last post by:
I am trying to remove all white spaces, tabs, newline, carriage return etc.. from a text file to make it as a one continous string. But the following code doesnot work. The file size is relatively...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.