Parsing Error
Trying to take a string then parse it to the correct format for decimal and dateonly for a CSV file yet the first record works fine but the subsequent records are showing an error? I'm very new to C# so having a bit of trouble figuring this one out
CS1503 Argument 1: cannot convert from 'string' to 'System.IFormatProvider?'
34 Replies
you seem seem a bit confused
why would you think you need to convert the value to a string and then parse it right back into a non-string data type?
at this point in the code are you trying to read in the file or export to the file?
I was not originally doing that but without ToString it was causing other errors. This is for the export part of the file after having made the changes.
You're trying to set
record.Amount
to record.Amount
But with extra steps
Same goes for other properties
You're setting them to... themselvesSo record amount is a string with say '100' and I want it to be a decimal with value '100.00' for example
Is the type of
record.Amount
a string or a decimal?And similar situation for date, taking '5/11/23' to '05/11/23'
Its a string
Then it is a string
Period
and I want it to be a decimal with two decimal places
You cannot assign a double or a boolean or a
Person
instance to a property of type string
You can only ever assign another stringOK
How would i take values that could be 100 or 87.12 and always make sure they come out with two decimal places, I don't mind if its a string, it just needs to have two decimal places
Same for the date, it needs to be zero padded
Store the values as their actual types
Integers stored as
int
, dates stored as DateOnly
, and so on
The, when displaying them, decide how should they be displayed
And only thenBut they are being brought in as strings from an existing CSV file that does not contain wholly dates or integers
A CSV file can be parsed into whatever you need it to be parsed
For example Amount comes in as " 100 | 98.16 | 55.1 " for example and I am trying to seperate it out into multiple records
Regardless, store in appropriate types
I dont think I can parse it as an integer if the cell contains a pipe and double quotations
Only
.ToString()
it with the desired format on display*sorry store not parse as an integer
Well, no, the format you have is garbage
Is this a school assignment, work assignment, personal project?
Can you share the source code?
But you can handle it manually
It's a personal project that will probably evolve into a work project. I'm practicing my C# on some simple work problems.
I can share my source code.
I'd start by having non-garbage data to work with
that would help us help you if you do share it (preferably via github repo link)
If at all possible
OK, I can't change the data coming in, it's from an external database
The whole point of the program is to make the data usable
You'll have to parse it manually. And if you have, as you say,
69 | 4.20 | 111.222
store that data in, say, double[]
type propertyI'll upload the CSV too so you can see what I mean
Appreciate the help, I spend most of my time with Powershell and JS so still learning the C# ropes
Lesson 1: C# has types, use them
404
The repo is private, probably
Whoops, now its public
Well, if you know which columns can store arrays... you can just parse them to arrays
I guess that makes sense
Just a bit frustrated with this project to be honest, I had it working great then trying to convert a single line item into multiple threw up all sorts of problems