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.AtEndOfStrea m <> True
line = df.ReadLine
account_no = trim(mid(line,3 ,9))
account_no = cleansedata(acc ount_no, 1)
customer_name = trim(mid(line,1 2,28))
customer_name = cleansedata(cus tomer_name, 1)
etc., etc.
Loop 8 2862
Do While df.AtEndOfStrea m <> True
line = df.ReadLine
If Not line = "" Then
account_no = trim(mid(line,3 ,9))
account_no = cleansedata(acc ount_no, 1)
customer_name = trim(mid(line,1 2,28))
customer_name = cleansedata(cus tomer_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******@sppin c.net> wrote in message
news:O$******** *****@tk2msftng p13.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.AtEndOfStrea m <> True line = df.ReadLine
account_no = trim(mid(line,3 ,9)) account_no = cleansedata(acc ount_no, 1)
customer_name = trim(mid(line,1 2,28)) customer_name = cleansedata(cus tomer_name, 1)
etc., etc.
Loop
Instead of looping through the stream and keeping a handle on the file
throughout, how about :
set fso = CreateObject("S cripting.FileSy stemObject")
set fs = fso.openTextFil e("path:\filena me.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******@sppin c.net> wrote in message
news:O$******** *****@tk2msftng p13.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.AtEndOfStrea m <> True line = df.ReadLine
account_no = trim(mid(line,3 ,9)) account_no = cleansedata(acc ount_no, 1)
customer_name = trim(mid(line,1 2,28)) customer_name = cleansedata(cus tomer_name, 1)
etc., etc.
Loop
> If Not line = "" Then
Careful, if there's an empty space there, this will fail...
--
Aaron Bertrand
SQL Server MVP http://www.aspfaq.com/
i am using sql server - what's this about bulk insert???
"Aaron Bertrand [MVP]" <aa***@TRASHasp faq.com> wrote in message
news:Ow******** *****@TK2MSFTNG P12.phx.gbl... Instead of looping through the stream and keeping a handle on the file throughout, how about:
set fso = CreateObject("S cripting.FileSy stemObject") set fs = fso.openTextFil e("path:\filena me.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******@sppin c.net> wrote in message news:O$******** *****@tk2msftng p13.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.AtEndOfStrea m <> True line = df.ReadLine
account_no = trim(mid(line,3 ,9)) account_no = cleansedata(acc ount_no, 1)
customer_name = trim(mid(line,1 2,28)) customer_name = cleansedata(cus tomer_name, 1)
etc., etc.
Loop
Here's one sample. http://www.sqlteam.com/item.asp?ItemID=3207
Ray at work
"JT" <je******@sppin c.net> wrote in message
news:eK******** ******@tk2msftn gp13.phx.gbl... i am using sql server - what's this about bulk insert???
"Aaron Bertrand [MVP]" <aa***@TRASHasp faq.com> wrote in message news:Ow******** *****@TK2MSFTNG P12.phx.gbl... Instead of looping through the stream and keeping a handle on the file throughout, how about:
set fso = CreateObject("S cripting.FileSy stemObject") set fs = fso.openTextFil e("path:\filena me.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******@sppin c.net> wrote in message news:O$******** *****@tk2msftng p13.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.AtEndOfStrea m <> True line = df.ReadLine
account_no = trim(mid(line,3 ,9)) account_no = cleansedata(acc ount_no, 1)
customer_name = trim(mid(line,1 2,28)) customer_name = cleansedata(cus tomer_name, 1)
etc., etc.
Loop
> 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/
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***@TRASHasp faq.com> wrote in message
news:uK******** ******@TK2MSFTN GP11.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/
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 space after a period. So Aspell
reads the last word of a sentence and the first word of the next sentence as
a single world, which gives an error, word not found.
Before sending the text to Aspell, i add a space after all the periods with:
|
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 as to how i should go about this.
thanks a lot,
Hp
|
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
|
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 in essence just removing the trailing space from each line?
|
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 cell-index put quotation
marks around the comma'd result.
Example csv line:
43.56,345.2,"1,285,100",45.6
| |
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 work for the file which
is located in a direcotry with a white space?
Thanks!
|
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 remove any number of excess space characters so that the sentence is rewritten correctly containing only 1 space character between individual words. However this program outputs each word on a separate line! Is there a problem with my loop?
Many...
|
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, call determined functions, and edit the data already present
What will you need to use the grid? A table with standard markup and an ID to call the script that will turn the table into a grid
Parameters:
tabelaID => id of the table that will...
|
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 smaller and hence I didn't use FILE::slurp. Please let me know the problem. Thanks.
#!/usr/bin/perl
local $/=undef;
open(FILE, "test.fa") || die ("Error\n");
$string = <FILE>;
$corrected_string =~ s/\n\r\t\s//g;
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |