Avatar of RadhaKrishnaKiJaya
RadhaKrishnaKiJaya
 asked on

StreamWriter not working

Hello Experts,
I am trying to generate an output file using StreamWriter in C# which contains Credit Card (CC) numbers.  As long as the CC Number is 15 digits long, the StreamWriter works just fine.  But when the CC Number length is 16 digits long, the StreamWriter replaces the last digit with 0 (zero).  Any idea how to fix it?  Please try to help.

Thank you very much in advance!
ASP.NET.NET ProgrammingC#

Avatar of undefined
Last Comment
RadhaKrishnaKiJaya

8/22/2022 - Mon
Shaun Vermaak

Can you post your code?
RadhaKrishnaKiJaya

ASKER
Hello Shaun,
Unfortunately I am not allowed to post the code here.  But the code is not different from other codes.  There is no parsing.  Just writing the data as it is.  This code in use for the last 15 years.  It happens only if the CC Number is more than 15 digits long.  So up to 15 digits I am not getting any issue.  Any digits more than 15 are replaced with 0s.  Hope that helps.  I think there is some limitation with the StreamWriter.

Thank you!
Fernando Soto

Are you using the StreamWriter with the correct size buffer size, one that will have the correct number of bytes. This is the only thing I can think of.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Éric Moreau

I really don't think that it is a limitation of the streamwriter, it has to come from your code.

I totally get that you cannot post all of your code here but can you at least post a dummy sample that replicates the issue?
RadhaKrishnaKiJaya

ASKER
Hello Eric Moreau,
Here is the code attached.

Thank you!
xxDummy.txt
RadhaKrishnaKiJaya

ASKER
Hello Fernando Soto,

How to set the buffer size of the  StreamWriter?

It is able to write even greater strings without any problem.  Only problem is with number longer than 15 digits.  How come it is possible?

Thank you!
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Éric Moreau

Which part of your code is not working properly? The WriteItem method?  I suspect your CreditCardEncrypt class to be the issue.  Add breakpoints to your code and debug it. You will be able to find out exactly where the value is transformed.
Fernando Soto

You are not using the StreamWriter method that specifically uses a defined buffer size. Seeming that you state that you can write less then or more then 16 characters I would tend to thing that maybe your code is manipulating the data.
ASKER CERTIFIED SOLUTION
RadhaKrishnaKiJaya

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Éric Moreau

It wasn't clear to me that you were using Excel in here. Most of us told that the issue was not the StreamWriter but it had to come from elsewhere.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Fernando Soto

Well it would of help if you would have given us the background info that you were getting the data from Excel. As I stated in my last post that I did not believe it was the StreamWriter but somehow cause by program manipulating the data well Excel was just doing that.
RadhaKrishnaKiJaya

ASKER
Fernando Soto and Eric Moreau, Data is not coming from Excel.  The C# program is creating an output file, which is and Excel file.  My apology for not mentioning about the Excel file.  Probably that would have fixed my issue earlier.  Thank you for your help.