Author Topic: INPUT from a file failing on a comma in the record  (Read 2623 times)

0 Members and 1 Guest are viewing this topic.

Offline George McGinn

  • Global Moderator
  • Forum Regular
  • Posts: 210
    • View Profile
    • Resume
INPUT from a file failing on a comma in the record
« 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!)

____________________________________________________________________
George McGinn
Theoretical/Applied Computer Scientist
Member: IEEE, IEEE Computer Society
Technical Council on Software Engineering
IEEE Standards Association
American Association for the Advancement of Science (AAAS)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: INPUT from a file failing on a comma in the record
« Reply #1 on: July 22, 2021, 04:40:51 pm »
Try LINE INPUT it doesnt stop on commas.

FellippeHeitor

  • Guest
Re: INPUT from a file failing on a comma in the record
« Reply #2 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.

Offline George McGinn

  • Global Moderator
  • Forum Regular
  • Posts: 210
    • View Profile
    • Resume
Re: INPUT from a file failing on a comma in the record
« Reply #3 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.
____________________________________________________________________
George McGinn
Theoretical/Applied Computer Scientist
Member: IEEE, IEEE Computer Society
Technical Council on Software Engineering
IEEE Standards Association
American Association for the Advancement of Science (AAAS)