string[] lines;
lines=File.ReadAllLines(pathfilenotepad);
......................EMS-SoftwareVersion-\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0...........................
String.Join(",",lines)
fails after this does not join lines
string[] lines;
lines=File.ReadAllLines(pathfilenotepad);
......................EMS-SoftwareVersion-\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0...........................
String.Join(",",lines)
fails after this does not join lines
I can't reproduce this issue. Can you share enough code to reproduce this issue?
Text file
......................EMS-SoftwareVersion-\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0...........................
This is a test
......................EMS-SoftwareVersion-\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0...........................
This is a test
......................EMS-SoftwareVersion-\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0...........................
This is a test
......................EMS-SoftwareVersion-\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0...........................
This is a test
Code
static void Main(string[] args)
{
string[] lines;
lines = File.ReadAllLines(pathfilenotepad);
string result = String.Join(",", lines);
Console.WriteLine(result);
}
Result
......................EMS-SoftwareVersion-\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0...........................,This is a test,......................EMS-SoftwareVersion-\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0...........................,This is a test,......................EMS-SoftwareVersion-\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0...........................,This is a test,......................EMS-SoftwareVersion-\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0...........................,This is a test
You could replace \0 first
string[] lines = {
"......................EMS-SoftwareVersion-\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0...........................",
"......................EMS-SoftwareVersion-\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0..........................."
};
var results = string.Join(",", lines.Select(x => x.Replace("\0", "")).ToArray());
Console.WriteLine(results);
Do you want to display \0 in the result string?
If this is the case, then you can follow Karen's approach, the difference is to replace \0 with \\0.
var results = string.Join(",", lines.Select(x => x.Replace("\0", "\\0")).ToArray());
This question has nothing to do with String.Join, but these characters are escaped.
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
10 people are following this question.
Insert a node as child ,before or after a node in nested dynamic JSON Node using C#
Visual Studio 2019: Undefined behavior in a C++/CLI wrapper project.
Example for how to get Package Metadata from Azure DevOps Rest-Api Artifacts using c#
How to collapse individual nested grids/stackpanels inside a grid?