Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente |
lang:csharp:readerwriter [2017/08/16 13:11] – [BinaryWriter] : ajout de BinaryReader root | lang:csharp:readerwriter [2020/04/27 08:04] (Version actuelle) – Conversion de <note> vers <WRAP> root |
---|
Il n'y a pas besoin du caractère ''null'' en fin de tableau. | Il n'y a pas besoin du caractère ''null'' en fin de tableau. |
| |
Par contre, cette méthode crée un ''string'' qui contient des caractères ''null''. Pour s'en débarrasser, il peut être utile de faire un ''.TrimEnd('\0')'' notamment pour que la méthode ''Length'' ne renvoie pas forcément ''5'' mais la vraie longueur du texte. | <WRAP center round info 60%> |
| Par contre, cette méthode crée un ''string'' qui contient des caractères ''null''. Pour s'en débarrasser, il peut être utile de faire un |
| <code csharp> |
| if (result.IndexOf('\0') != -1) |
| { |
| result = result.Substring(0, result.IndexOf('\0')); |
| } |
| </code> |
| </WRAP> |
| |
[[https://stackoverflow.com/questions/864246/getting-null-terminated-string-from-system-text-encoding-unicode-getstring|Source]], {{ :lang:csharp:readerwriter:net_-_getting_null_terminated_string_from_system.text.encoding.unicode.getstring_-_stack_overflow.maff |Archive}} | |
=====Remplacement dans un fichier via regex/pattern===== | =====Remplacement dans un fichier via regex/pattern===== |
Sans réfléchir : | Sans réfléchir : |
{ | { |
string tempLineValue; | string tempLineValue; |
using (FileStream inputStream = File.OpenRead(originalFile) ) | FileStream inputStream = null; |
| try |
{ | { |
| inputStream = File.OpenRead(originalFile) |
using (StreamReader inputReader = new StreamReader(inputStream)) | using (StreamReader inputReader = new StreamReader(inputStream)) |
{ | { |
| inputStream = null; |
using (StreamWriter outputWriter = File.AppendText(outputFile)) | using (StreamWriter outputWriter = File.AppendText(outputFile)) |
{ | { |
} | } |
} | } |
| } |
| finally |
| { |
| if (inputStream != null) |
| inputStream.Dispose(); |
} | } |
} | } |
</code> | </code> |
| |
[[http://stackoverflow.com/questions/1915632/open-a-file-and-replace-strings-in-c-sharp|Source]], {{ :lang:csharp:readerwriter:open_a_file_and_replace_strings_in_c_-_stack_overflow.maff |Archive}} | [[https://stackoverflow.com/questions/1915632/open-a-file-and-replace-strings-in-c-sharp|Open a file and replace strings in C# - Stack Overflow]] {{ :lang:csharp:readerwriter:open_a_file_and_replace_strings_in_c_-_stack_overflow_2020-04-27_7_57_16_am_.html |Archive du 16/12/2009 le 27/04/2020}} |
| |
| [[https://rules.sonarsource.com/csharp/RSPEC-3966|Objects should not be disposed more than once]] {{ :lang:csharp:readerwriter:c_objects_should_not_be_disposed_more_than_once_2020-04-27_7_58_20_am_.html |Archive le 27/04/2020}} |
=====Ajout d'un texte à l'intérieur d'un fichier===== | =====Ajout d'un texte à l'intérieur d'un fichier===== |
Pas de méthode miracle malheureusement. | Pas de méthode miracle malheureusement. |
</code> | </code> |
| |
[[http://stackoverflow.com/questions/14290642/how-to-insert-lines-into-the-middle-of-a-text-file#comment19846546_14290642|Source]], {{ :lang:csharp:readerwriter:c_-_how_to_insert_lines_into_the_middle_of_a_text_file_-_stack_overflow.maff |Archive}} | [[https://stackoverflow.com/questions/14290642/how-to-insert-lines-into-the-middle-of-a-text-file|c# - How to insert lines into the middle of a text file_ - Stack Overflow]] {{ :lang:csharp:readerwriter:c_-_how_to_insert_lines_into_the_middle_of_a_text_file_-_stack_overflow_2020-04-27_7_57_24_am_.html |Archive du 12/01/2013 le 27/04/2020}} |
| |
=====Chargement d'un fichier texte en mémoire===== | =====Chargement d'un fichier texte en mémoire===== |
</code> | </code> |
| |
[[http://stackoverflow.com/questions/8416413/create-new-file-with-specific-size|Source]], {{ :lang:csharp:readerwriter:c_-_create_new_file_with_specific_size_-_stack_overflow.maff |Archive}} | [[https://stackoverflow.com/questions/8416413/create-new-file-with-specific-size|c# - Create new file with specific size - Stack Overflow]] {{ :lang:csharp:readerwriter:c_-_create_new_file_with_specific_size_-_stack_overflow_2020-04-27_7_57_33_am_.html |Archive du 07/12/2011 le 27/04/2020}} |