C
C#3mo ago
Mist

✅ Program csv extraction

I created a program but when it extracts as a csv file its got a  symbol and one of the values extract into two separate cells
No description
36 Replies
Angius
Angius3mo ago
For the first issue, my bet is encoding differences. Make sure the encodings match, or convert them if needed. Could be the CSV is encoded in ASCII, and the output wants UTF8, for example. Or the other way around. For the other issue, could it be that a comma is used for a thousands separator? 1,400? Because "CSV" stands for "comma-separated values", so
rent,300.00
food,300.00
remaining,1,400.00
rent,300.00
food,300.00
remaining,1,400.00
will be treated as
rent | 300.00 |
food | 300.00 |
remaining | 1 | 400.00
rent | 300.00 |
food | 300.00 |
remaining | 1 | 400.00
Mist
Mist3mo ago
i tried removing the comma but it made it so it would all be in the first cell
leowest
leowest3mo ago
rent,300.00
food,300.00
remaining,"1,400.00"
rent,300.00
food,300.00
remaining,"1,400.00"
Mist
Mist3mo ago
Oh so just making it a quote would work
leowest
leowest3mo ago
yes because its one way CSV uses to ignore a comma within a column ideally you should use a library like CSVHelper it will make your life easier
Mist
Mist3mo ago
Thank you I don’t really do a lot of projects where they extract
MODiX
MODiX3mo ago
Use the /close command to mark a forum thread as answered
Mist
Mist3mo ago
what would i do about the A as i have no idea what that is even ment to be
leowest
leowest3mo ago
its probably currency symbol you're not using the right encoding so without more details about how you're writing that file hard to tell
Mist
Mist3mo ago
can i share my code on this thread
leowest
leowest3mo ago
$paste to the site below if possible
MODiX
MODiX3mo ago
If your code is too long, you can post to https://paste.mod.gg/ and copy the link into chat for others to see your shared code!
leowest
leowest3mo ago
you can also add multiple files to it if u have to no zippped files
Mist
Mist3mo ago
MODiX
MODiX3mo ago
leowest
REPL Result: Success
CultureInfo cultureInfo = CultureInfo.CreateSpecificCulture("en-US");
Thread.CurrentThread.CurrentCulture = cultureInfo;
var v = 1400.00m;
v.ToString("C2")
CultureInfo cultureInfo = CultureInfo.CreateSpecificCulture("en-US");
Thread.CurrentThread.CurrentCulture = cultureInfo;
var v = 1400.00m;
v.ToString("C2")
Result: string
$1,400.00
$1,400.00
Quoted by
<@1102729783969861782> from #bot-spam (click here)
Compile: 326.461ms | Execution: 44.050ms | React with ❌ to remove this embed.
leowest
leowest3mo ago
as you can see C2 is a currency formatter, it adds the symbol so I assume your streamwriter is not using the proper encoding for it to display are you using .net framework?
Mist
Mist3mo ago
yea on visual studio oh no sorry im just doing console app
leowest
leowest3mo ago
try changing this
StreamWriter(fileName))
StreamWriter(fileName))
to
StreamWriter(fileName, Encoding.UTF8))
StreamWriter(fileName, Encoding.UTF8))
Mist
Mist3mo ago
on visual studio
leowest
leowest3mo ago
yes but if u right click your project in the solution explorer of visual studio and click properties does it say .net framework or .net 8
Mist
Mist3mo ago
oh it says net framework
leowest
leowest3mo ago
ok, try what I said above
Mist
Mist3mo ago
will do thank you its now saying it cant convert from string to system.io.stream
leowest
leowest3mo ago
can you show your new code
Mist
Mist3mo ago
Mist
Mist3mo ago
this is it now
leowest
leowest3mo ago
ah right my bad you're on .net framework it is
StreamWriter(fileName, false, Encoding.UTF8))
StreamWriter(fileName, false, Encoding.UTF8))
sorry needs to be false in your case u also need to change writer.WriteLine($"{expense.Key},\"{expense.Value:C2}\"");
Mist
Mist3mo ago
i changed it its all worked but the remaining ballance is still messing up where it displays like this
Mist
Mist3mo ago
Mist
Mist3mo ago
No description
leowest
leowest3mo ago
well yeah u'r not adding "" for the remaining and its also missing a comma
Mist
Mist3mo ago
oh i thought i was changing it to that what you sent
leowest
leowest3mo ago
u did but did u forgot what we talked about
leowest
leowest3mo ago
No description
leowest
leowest3mo ago
you're not adding neither the comma nor the quotes for the remaining so how do u expect it to print right I pushed u half way u need to push your self the other half 🙂
Mist
Mist3mo ago
i will do my best thank you for the help