C
C#8mo 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
Angius8mo 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
MistOP8mo ago
i tried removing the comma but it made it so it would all be in the first cell
leowest
leowest8mo ago
rent,300.00
food,300.00
remaining,"1,400.00"
rent,300.00
food,300.00
remaining,"1,400.00"
Mist
MistOP8mo ago
Oh so just making it a quote would work
leowest
leowest8mo 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
MistOP8mo ago
Thank you I don’t really do a lot of projects where they extract
MODiX
MODiX8mo ago
Use the /close command to mark a forum thread as answered
Mist
MistOP8mo ago
what would i do about the A as i have no idea what that is even ment to be
leowest
leowest8mo 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
MistOP8mo ago
can i share my code on this thread
leowest
leowest8mo ago
$paste to the site below if possible
MODiX
MODiX8mo 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
leowest8mo ago
you can also add multiple files to it if u have to no zippped files
Mist
MistOP8mo ago
MODiX
MODiX8mo 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
leowest8mo 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
MistOP8mo ago
yea on visual studio oh no sorry im just doing console app
leowest
leowest8mo ago
try changing this
StreamWriter(fileName))
StreamWriter(fileName))
to
StreamWriter(fileName, Encoding.UTF8))
StreamWriter(fileName, Encoding.UTF8))
Mist
MistOP8mo ago
on visual studio
leowest
leowest8mo 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
MistOP8mo ago
oh it says net framework
leowest
leowest8mo ago
ok, try what I said above
Mist
MistOP8mo ago
will do thank you its now saying it cant convert from string to system.io.stream
leowest
leowest8mo ago
can you show your new code
Mist
MistOP8mo ago
Mist
MistOP8mo ago
this is it now
leowest
leowest8mo 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
MistOP8mo ago
i changed it its all worked but the remaining ballance is still messing up where it displays like this
Mist
MistOP8mo ago
Mist
MistOP8mo ago
No description
leowest
leowest8mo ago
well yeah u'r not adding "" for the remaining and its also missing a comma
Mist
MistOP8mo ago
oh i thought i was changing it to that what you sent
leowest
leowest8mo ago
u did but did u forgot what we talked about
leowest
leowest8mo ago
No description
leowest
leowest8mo 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
MistOP8mo ago
i will do my best thank you for the help
Want results from more Discord servers?
Add your server