StreamWriter not working

RadhaKrishnaKiJaya
RadhaKrishnaKiJaya used Ask the Experts™
on
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!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Shaun VermaakTechnical Specialist
Awarded 2017
Distinguished Expert 2018

Commented:
Can you post your code?

Author

Commented:
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 SotoRetired
Distinguished Expert 2017

Commented:
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.
Amazon Web Services

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

Éric MoreauSenior .Net Consultant
Top Expert 2016

Commented:
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?

Author

Commented:
Hello Eric Moreau,
Here is the code attached.

Thank you!
xxDummy.txt

Author

Commented:
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!
Éric MoreauSenior .Net Consultant
Top Expert 2016

Commented:
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 SotoRetired
Distinguished Expert 2017

Commented:
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.
First of all thank you all for your time and trying to help.  Here is the solution.

https://support.microsoft.com/en-us/help/269370/last-digits-are-changed-to-zeroes-when-you-type-long-numbers-in-cells
Éric MoreauSenior .Net Consultant
Top Expert 2016

Commented:
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.
Fernando SotoRetired
Distinguished Expert 2017

Commented:
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.

Author

Commented:
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.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial