QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: George McGinn on July 22, 2021, 04:40:03 pm

Title: INPUT from a file failing on a comma in the record
Post by: George McGinn on July 22, 2021, 04:40:03 pm
Hello,

I am running into an issue were I am reading a record from a file, and part of the record there is a coma. I am not getting the entire record.

The file was created after a mySQL select returned a number of rows. I piped them to a file to test various ways to process them.

After the INPUT #1, qString$, the results are truncated from the comma on. It is not until I do another INPUT #1, qString$ that I get the rest of the record.

Here is one of the records, and the result from my program.

Record (TAB Delimited, but not the issue here as it still occurs when I change the TAB to a pipe):
Quote
7   Blondel père et fils   Frédérique Citeaux   24, place Kléber   Strasbourg   67000   France

This is what I am getting:
Quote
Length of qString$:  47
7   Blondel père et fils   Frédérique Citeaux   24

After the next INPUT, I get (With the results):
Quote
Length of qString$:  37
place Kléber   Strasbourg   67000   France

If I put the entire record in quotes, it works.

Is this a bug? Shouldn't I get the entire record, commas and all, as they are strings?

(And the answer is not to put the record in Quotes, as the results from mySQL does not do that as far as I know!)

Title: Re: INPUT from a file failing on a comma in the record
Post by: bplus on July 22, 2021, 04:40:51 pm
Try LINE INPUT it doesnt stop on commas.
Title: Re: INPUT from a file failing on a comma in the record
Post by: FellippeHeitor on July 22, 2021, 05:13:26 pm
if a **value** includes commas, enclose the value in "quotation marks". INPUT for reading from a file reads it as a CSV - and that's one of the format's specifications.
Title: Re: INPUT from a file failing on a comma in the record
Post by: George McGinn on July 22, 2021, 05:55:17 pm
@bplus - Thanks, that did it (I keep forgetting about LINE INPUT as I usually only use it for Binary files).

@FellippeHeitor - I will remember that. Unfortunately, dealing with data created by an external process does not always afford me the ability to put quotes around strings. Knowing that INPUT was designed to read CSV files is a help.

If I am reading in string data, LINE INPUT should be used. If I am reading/input to numeric variable(s) or comma-separated variables, then INPUT is the right statement.

Thanks.