|
Not as silly as you may think. I worked on a project once where the client provided long lists of products with decimal based prices, but where the database was setup to hold prices based in cents, not decimal dollars. A crappy design it was, but hands were tied they were.
I wasn't, now I am, then I won't be anymore.
|
|
|
|
|
Pierre besquent wrote: I wanna have
..you want fries with that?
I are Troll
|
|
|
|
|
yes please, as long as they don't add points.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
You might need a file for that.
|
|
|
|
|
please make sure there is no period in the filename!
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
thank u for all,
u really let me laughing very much with all u jokes responses
that is the real help
I found a solution my self:
double x = 1458752.10254000;
string s = x.ToString(System.Globalization.CultureInfo.InvariantCulture).Replace(".",string.Empty);
Console.WriteLine(s);
Console.ReadLine();
the output is :145875210254
thank u very much for u big effort in creating jokes.
|
|
|
|
|
Let's say that your Double is double lifeSpan.
string ls = lifeSpan.ToString().Replace(".","");
|
|
|
|
|
I've created a abstract class that is based upon a BindingList<t>, then I have classes based upon that abstract that should populate the list.
The idea being if you instaniate these secondary classes you have a useable list.
This works in code, creating a new class does populate the list.
However I know want to move to the next step, and use the seconday class as a binding source. But the problem is that binding doesn't seem to call the constructor of the class, and so my list is empty. (apart from that the binding seems to be working)
I can work around this by adding a BindingSource.DataSource = new SecondaryClass(); to the form etc...basically I'd like to avoid this step if possible?
Hopefully that makes sense?!?
modified on Sunday, March 27, 2011 7:54 AM
|
|
|
|
|
I am sorry, but you will have to go through that extra step.
|
|
|
|
|
Hi,
I write a txt file using streamwriter class :
StreamWriter monStreamWriter = new StreamWriter(myPath, true, System.Text.Encoding.ASCII);
monStreamWriter.WriteLine(strEnteteHead + Inserer_Espaces(8) + entite.NumSIRET + Inserer_Espaces(7) + strDate + domicilationbancaireE + referenceVir + Inserer_Espaces(15) + strEuro + Inserer_Espaces(5) + guichetE + compteE + Inserer_Espaces(20) + agenceE );
monStreamWriter.WriteLine(strEnteteBody +Inserer_Espaces(8) + agenceD + reglement.ID + reglement.Nom + reglement.Banque + Inserer_Espaces(12) + agenceD + compteD + reglement.Montant + agenceD);
monStreamWriter.WriteLine(strEnteteSum + reglement.Montant.ToString());
monStreamWriter.WriteLine();
monStreamWriter.WriteLine ();
the problem that i wanna that i have a new line every monstreamWriter.writeline. That is what i don't have when I open my txt file.
what is the problem??
ty
modified on Friday, March 18, 2011 6:05 AM
|
|
|
|
|
Not sure what your problem is; this:
string fn="swl.txt";
using (StreamWriter sw=new StreamWriter(fn, true, Encoding.ASCII)) {
sw.WriteLine("line 1");
sw.WriteLine("line 2");
sw.WriteLine();
sw.WriteLine();
sw.WriteLine("line 5");
sw.WriteLine("line 6");
sw.WriteLine();
sw.WriteLine();
}
string[] sa=File.ReadAllLines(fn);
foreach (string s in sa) log(s);
log("done");
works just fine for me, as it generates:
16:14:29.329 CPTest.log-59 line 1
16:14:29.335 CPTest.log-59 line 2
16:14:29.341 CPTest.log-59
16:14:29.347 CPTest.log-59
16:14:29.353 CPTest.log-59 line 5
16:14:29.358 CPTest.log-59 line 6
16:14:29.364 CPTest.log-59
16:14:29.369 CPTest.log-59
16:14:29.375 CPTest.log-59 done
The obvious way to make things fail would be by reassigning the streamwriter's NewLine property.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Hi Luc,
I don't understand u answer "The obvious way to make things fail would be by reassigning the streamwriter's NewLine property"
Ty
|
|
|
|
|
For a StreamWriter sw
sw.WriteLine(something);
is equivalent to
sw.Write(something);
sw.Write(sw.NewLine);
and NewLine by default equals Environment.NewLine , which holds "\r\n" on Windows.
So if you set sw.NewLine=""; then there will not be any line breaks.
BTW: as usual, it is all in the documentation.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
I don't think the problem is your code but with notepad.
Notepad (which I think you're using) doesn't accept newline characters very well or simply doesn't show.
Try opening it with wordpad or word, that might 'fix' your problem.
|
|
|
|
|
hi,
U answer works well in first use (opening with word pad) but when I repeat the action (opening file with wordpad) still the same problem (all lignes in same ligne).This what I have
ty
|
|
|
|
|
|
absolutely not.
"have a coffee" would be better advice.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Why not? He doesn't seem to be closing the stream. Maybe those missing lines are still in the buffer?
|
|
|
|
|
flush does not close.
close (or dispose) does flush. (hence: the sequence flush+close does not make sense).
if the file wasn't closed, the file would be most likely be unreadable.
from his (rather incomplete) description, I get it there is data in the file, so it got closed, and an extra flush wouldn't change a thing.
flush is abused a lot; there is exactly one situation where an unnecessary flush does solve a problem that is caused by an entirely different mistake in the code, but there are no signs it applies here.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Data can end up in the file, even if it is not closed. When the StreamWriter buffer fills (default: 4KB), that portion is written to file.
To modify your earlier example (omitting the "using" statement, thereby denying a close):
string fn = "swl.txt";
StreamWriter sw = new StreamWriter(fn, true, Encoding.ASCII);
sw.WriteLine("line 1");
sw.WriteLine("line 2");
sw.WriteLine();
sw.WriteLine();
sw.WriteLine("line 5");
sw.WriteLine("line 6");
sw.WriteLine();
sw.WriteLine();
Nothing is written to the file. However, when I use:
string fn = "swl.txt";
StreamWriter sw = new StreamWriter(fn, true, Encoding.ASCII);
sw.WriteLine("line 1");
sw.WriteLine("line 2");
sw.WriteLine();
sw.WriteLine();
sw.WriteLine("line 5");
sw.WriteLine("line 6");
for (int i = 0; i < 5000; i++) sw.Write("X");
sw.WriteLine();
sw.WriteLine();
sw.Write("Will not go in file.");
I have exceeded the buffer, and the first 4K writes. When I run this code, I get a file with the lines up to the "for" statement, plus many "X" characters, but none of the later lines are "written". The file is readable, just incomplete after the program closes.
|
|
|
|
|
I know all that. The logical conclusion is one needs to close, not flush, the file (or better: all objects that are to contribute to the file content, in the reverse order in which they were opened). And that is what I did in my very first reply.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Hi Luc,
I read u discussion but i can't conclude the solution I can adopt even after adding this 2 lines of code
string endOfLine = new string (new char [] { (char)0x0D, '\n' });
monStreamWriter.WriteLine(strEnteteSum + Inserer_Espaces (8) + Inserer_Espaces (6) + Inserer_Espaces (84) + montant + endOfLine);
but still not organized right now
ty
|
|
|
|
|
if you want to solve a problem, any problem, the first thing to do it to describe it as accurately as possible. "not organized right" is in no way an accurate description, I can't help any further based on just that.
Use the right tool to look at the output and tell us what it is and what you want it to be. For problems with CR/LF Notepad probably isn't the right tool, at best you'd use a Hex Viewer/Hex Editor as Pete already told you.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Hi Luc,
I want to have a file having as formats DOS/Windows and so its lignes have as end of line the two characters CR+LF.
When I open my file with Excel, all lines are in the same line, no considering of endofline that I added to my code and the use of the stringbulder class like this :
StringBuilder lineBuilder = new StringBuilder ();
lineBuilder .Append (headLine);
lineBuilder.Append (endOfLine);
Ty
|
|
|
|
|
if you run on Windows, never touch any NewLine property, and simply create a text file in a normal way, with data that is ASCII representable, then the file will be an ASCII file (8b/char) and every WriteLine will insert a CR+LF.
If you aren't getting CR+LF it tells me you are doing something special, I don't know what as there is a lot you still haven't told. If you need any further help, state your operating system, your .NET version, the kind of characters you are having, and all the code of the smallest app that goes wrong.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|