Read file from multiple encoding in c# ENV: C#, VStudio 2013, 4.5 Framework, Winforms, nHapi 2.3 dll  I really need help on this. I have tried soo many things and did alot of research with my best friend google ;-). But no luck.  I'm building a HL7 sender tools and I'm reading files from a folder. My files come from multiple sources and I found that they have different encoding : I have open them with notepadd++ and they can be ainsi, utf8 et utf8 witout BOM. My files also contains special caracters like é,à,ç,ô, .... but they always put weird caracter when I read the file with this line : var hl7message = File.ReadAllText(e.Node.Name);  The only time I don't have any problem is when the source file is encoded in UTF8 with the BOM.  Is there a way that no matter what the source file encoding is, I can alway read the file in a string and have the special caracter show correctly.  This is the main portion of my code :  var hl7message = File.ReadAllText(FileName); var llphl7message = Convert.ToChar(11).ToString() + newmessage + Convert.ToChar(28).ToString() + Convert.ToChar(13).ToString();  // Get the size of the message that we have to send. Byte[] bytesSent = Encoding.Default.GetBytes(llphl7message); Byte[] bytesReceived = new Byte[256];  // Create a socket connection with the specified server and port. Socket s = ConnectSocket(txtParamServer.Text, Convert.ToInt32(txtParamPort.Text)); // If the socket could not get a connection, then return false. if (s == null) {                     txtLog.Text = txtLog.Text + "[" + DateTime.Now + "] [ERR] Serveur " + txtParamServer.Text + " sur le port " + txtParamPort.Text + " est non disponible" + "\r\n";                     return false; }  // Send message to the server. s.Send(bytesSent, bytesSent.Length, 0);   Thank you for you help Sorry for the bad english : not my main language  Richard
How can I detect the encoding/codepage of a text file In our application, we receive text files (.txt, .csv, etc.) from diverse sources. When reading, these files sometimes contain garbage, because the files where created in a different/unknown codepage.  Is there a way to (automatically) detect the codepage of a text file?   The detectEncodingFromByteOrderMarks, on the StreamReader constructor, works for UTF8  and other unicode marked files, but I'm looking for a way to detect code pages, like ibm850, windows1252.     Thanks for your answers, this is what I've done.  The files we receive are from end-users, they do not have a clue about codepages. The receivers are also end-users, by now this is what they know about codepages: Codepages exist, and are annoying.  Solution:    Open the received file in Notepad, look at a garbled piece of text. If somebody is called François or something, with your human intelligence you can guess this. I've created a small app that the user can use to open the file with, and enter a text that user knows it will appear in the file, when the correct codepage is used.  Loop through all codepages, and display the ones that give a solution with the user provided text.  If more as one codepage pops up, ask the user to specify more text.
Was the blue fire from Crimes of Grindlewald Fiendfyre? In Crimes of Grindlewald, Grindelwald uses a powerful blue flame that takes on the shape of monsters. Was this Fiendfyre? Can the Artificer Artillerist's tiny-sized Eldritch Cannon that is not held in hand still ride or be carried elsewhere on the body? There is a way to add custom split normal use Python API? I can't find a way to achieve custom split normal effect. I want to use python (mesh normal/hard edge or soft edge) data collected from Maya then write to Blender mesh.    How to do it using the following Python API and how?  bpy.data.meshes[objName].normals_split_custom_set_from_vertices  bmesh module I have two examples of different scenarios that are confusing to me.  First, if I have a 1/1 creature with first strike and deathtouch, and my opponent blocks it with a 2/2 creature, will my creature die? I can see two alternative ways this could play out and I'm not sure which is correct.   My creature deals his first strike damage, immediately killing the opponent's creature before he is able to deal combat damage as a state-based effect. My creature deals his first strike damage, which would normally be lethal due to deathtouch, but state-based effects are not checked, and thus the opposing creature deals his damage and both die.   I'm almost positive in this case that it's the first option above.  What gets trickier is, for example, if a creature has first strike and a triggered ability "Whenever this creature deals combat damage to a creature, return that creature to its owner's hand."  This is not a state-based effect, but rather uses the stack. Similar to above, there are two possibilities.   My creature deals his first strike damage, and his triggered ability is placed on the stack. The stack waits to resolve until after all combat damage is dealt, so the opposing creature still kills mine. My creature deals his first strike damage, and his triggered ability is placed on the stack. Both players now gain priority between first strike and combat damage (which I don't think normally happens, thus my confusion). The stack finishes resolving, and the opponent's creature doesn't have a chance to deal damage.   Can someone clarify this area of the rules? Unexpected output for this following code Is it correct to say "I write children books" (not possessive case)? Although Children's books is what everybody says, I would like to understand why the genitive case is applied in such case.  If I write books for children, children is an adjective here; not the owners of my book! The word "children" just defines or characterizes the type of books I write. Therefore, it's an adjective.   So, I understand that genitive/possessive case ("I write children's book")  is incorrect grammar.  My question is: is the genitive case here really accepted as right? If I use "I write children books" (following the grammar principle) as as I say "I write pets books" (books about pets, and not possessions of pets) - would I be incorrect? Why? If $x+y+z=xyz$, prove $\frac{2x}{1-x^2}+\frac{2y}{1-y^2}+\frac{2z}{1-z^2}=\frac{2x}{1-x^2}\times\frac{2y}{1-y^2}\times\frac{2z}{1-z^2}$ given that $x^2~,~y^2~,~z^2\ne1$  I came across this question in an ancient ($19$th century) Trigonometry book, and this is the method they use to prove the result (please note: I understand this method fully): Let $x=\tan A$ ,$~y=\tan B$ and $z=\tan C$ which is acceptable without any loss of generality. This means that we are saying that $$\tan A+\tan B+\tan C=\tan A\tan B\tan C$$ Consider $\tan (A+B+C)$: $$\tan (A+B+C)=\frac{\tan A+\tan B+\tan C-\tan A\tan B\tan C}{1- \tan A \tan B- \tan C \tan A - \tan B \tan C}$$ So if $~\tan A+\tan B+\tan C=\tan A\tan B\tan C~~$ then $~~\tan (A+B+C)=0$. Hence, let $~A+B+C=\pi$. Now consider $\tan (2A+2B+2C)$: $$\tan (2A+2B+2C)=\frac{\tan 2A+\tan 2B+\tan 2C-\tan 2A\tan 2B\tan 2C}{1- \tan 2A \tan 2B- \tan 2C \tan 2A - \tan 2B \tan 2C}=0$$ $$\implies \tan 2A+\tan 2B+\tan 2C=\tan 2A\tan 2B\tan 2C$$ $$\implies \frac{2\tan A}{1-\tan^2 A}+\frac{2\tan B}{1-\tan^2 B}+\frac{2\tan C}{1-\tan^2 C}=\frac{2\tan A}{1-\tan^2 A}\times\frac{2\tan B}{1-\tan^2 B}\times\frac{2\tan C}{1-\tan^2 C}$$ $$\therefore\frac{2x}{1-x^2}+\frac{2y}{1-y^2}+\frac{2z}{1-z^2}=\frac{2x}{1-x^2}\times\frac{2y}{1-y^2}\times\frac{2z}{1-z^2}$$ as required.  My question is, is there any other way of proving this without this rather heavy use of trigonometry? I also would prefer not to work through heaps of algabraic manipulation and expansion to obtain the required result, although if that's necessary I will put up with it ;) Thank you for your help. Now that tags have this erm...  which appears when you move your mouse over them (try it! ), one question remains: What in the billion blue blazes does the 'subscribe' button do?   It's not RSS, since a traditional RSS feed link appears beside it, and clicking on it seems to increment the number of subscriber by one, but other than that scouring over the Stack Overflow UI does not appear to reveal anything. Surely this feature would have more use than serving as a popularity contest for the tags? Why does this test program result in a java.lang.IllegalMonitorStateException?  public class test {     static Integer foo = new Integer(1);     public static void main(String[] args) {         synchronized(foo) {             foo++;             foo.notifyAll();         }         System.err.println("Success");     } }   Result:  Exception in thread "main" java.lang.IllegalMonitorStateException         at java.lang.Object.notifyAll(Native Method)         at test.main(test.java:6) Why was C-3PO's memory wiped, but not R2-D2's? In Revenge of the Sith after Luke and Leia are born, they are sent to separate parts of the galaxy. The droids are given to Captain Antilles, with the instructions to clean them up, and have C-3PO's memory wiped. Why just C-3PO's and not also R2-D2's?   Initially I thought it was due to R2-D2's inability to communicate verbally, but he not only can communicate via text message (as seen in The Empire Strikes Back I believe), but we see other characters understanding his blips and bleeps as well. Which kind of pointer do I use when? Integral $ \int_{-\infty}^{\infty}\frac{x^{2}}{\cosh\left(x\right)}\,{\rm d}x $ I need to compute the improper integral $$ \int_{-\infty}^{\infty}\frac{x^{2}}{\cosh\left(x\right)}\,{\rm d}x $$ using contour integration and possibly principal values.  Trying to approach this as I would normally approach evaluating an improper integral using contour integration doesn't work here, and doesn't really give me any clues as to how I should do it. This normal approach is namely evaluating the contour integral $$ \oint_{C}{\frac{z^2}{\cosh\left(z\right)}\mathrm{d}z} $$ using a semicircle in the upper-half plane centered at the origin, but the semicircular part of this contour integral does not vanish since $\cosh\left(z\right)$ has period $2\pi\mathrm{i}$ and there are infinitely-many poles of the integrand along the imaginary axis given by $-\pi\mathrm{i}/2 + 2n\pi\mathrm{i}$ and $\pi\mathrm{i}/2 + 2n\pi\mathrm{i}$ for $n \in \mathbb{Z}$. The residues of the integrand at these simple poles are $-\frac{1}{4}\mathrm{i}\pi^{2}\left(1 - 4n\right)^{2}$ and $\frac{1}{4}\mathrm{i}\left(4\pi n + \pi\right)^{2}$, so that even when we add up all of the poles, we have the sum $4\pi^{2}\mathrm{i}\sum_{n = 0}^{\infty}\,n$, which clearly diverges.  Any hints would be greatly appreciated. I'd like to run a game of , but I'm not sure how many dice I roll when the characters face various challenges. I'm under the impression that it's supposed to be the same number of dice the character uses, but that seems to make impossible tasks far too easy to perform. Is there a general rule saying how many dice the GM rolls against a character's attempt at a given task?  Should the GM's dice equal the character's dice, or should the GM's dice vary depending on the task's difficulty? I'm trying to create a bowling animation and I want the ball to hit the pins. I already added the Rigid Body physics to the objects but can't get the ball to move.  Obviously I could just add keyframes but   that seems to interfere with the Rigid Body physics it doesn't look too realistic.   Is there a way to add some kind of motion to the ball? How to add a description to the user name input field in the registration form? I want a description under the user name input field in the Wordpress registration form like in the next example. How can I do this?  //create an extra field in login page for invitation code add_action( 'register_form', 'add_invitation_code_field' );  function add_invitation_code_field() {    ?&gt;       &lt;p&gt;          &lt;label for="invitation_code"&gt;             Invitation code             &lt;input id="invitation_code" class="input" type="text" size="20" value="" name="invitation_code"/&gt;             &lt;span class="description"&gt;&lt;?php _e("Description text"); ?&gt;&lt;/span&gt;          &lt;/label&gt;       &lt;/p&gt;    &lt;?php } how to Query parent to child I have process in salesforce in such a way opportunity we can relate this opportunity to this lookup field parent_opportunity__c . Which relates opportunity to other parent opportunity.  I want to write a query parent to child :  select id,(select id from opportunity where parent_opportunity__c!=null) from opportunity where parent_opportunity__c=null   I have worked with different scenarios i cant able to crack it  select id,name,(select id,name from parent_opportunity__r) from opportunity this is showing error and   select id,name,(select id,name from opportunity) from parent_opportunity__c this is also error I need a way to determine the type of an HTML element in JavaScript. It has the ID, but the element itself could be a &lt;div&gt;, a &lt;form&gt; field, a &lt;fieldset&gt;, etc. How can I achieve this? Adding a Method to an Existing Object Instance How to give an image or video a TV screen effect? How do I fix the GPG error "NO_PUBKEY"?