Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
What does this code mean? Somehow it generates a .csv file on my side but I cannot seem to find it. I am using it as a data source.
public CSVRepository()
{
var filename = ConfigurationManager.AppSettings["CSVFileName"];
path = AppDomain.CurrentDomain.BaseDirectory + filename;
}
The code runs as the constructor of a class. It looks in an app.config xml file to find a CSVFileName xml element. It uses the value of the element as a filename (no path, just the name). Then it looks up the path where the program is running, appends the filename to that path, and sets the result to a member field in the class that will be used by other code in the class to write out your csv file.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed last year.
Improve this question
I'm using csharp in console.net
I want to get a txt file from the user as input
But I do not want the text inside the txt file to be displayed to the user
Instead, I want the text to be hidden and the number of lines to be displayed instead
If I understood you fine, you want to count the number of lines in the txt file, right?
A basic approach could be:
string[] fileLines = System.IO.File.ReadAllLines("<path to the file>");
if (fileLines != null)
Console.WriteLine($"The file has {fileLines.Length} lines.");
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I know how to put string list to a .txt file for example:
//nw_TCList is a string list
string nwFinal = String.Join("\n", nw_TCList.ToArray());
System.IO.File.WriteAllText(nwPath, nwFinal);
So my question is how to put this string list file to a .list file?
-------------Question update
Thank you for all the reply, nwPath is my txt file address. (#"c:\abc\name.txt")
Problem solved! just change .txt to .list, LOL, i was thinking how to convert txt file to list file before, haha.
.list is just Extension so don't worry about that
there is direct method to write Array to file
System.IO.File.WriteAllLines(nwPath, nw_TCList);
And If you want to have .list Extension
give that in path param
E.g.
System.IO.File.WriteAllLines("D://Data.list", nw_TCList);
that did trick for me
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
The requirement is that a user can choose a file name format from predefined tags.
Example
InvoiceNo Date VendorName
if user chooses InvoiceNo-Date-Vendorname then the file name should be generated like: 001-20170512-ABCElectronics
if user chooses InvoiceNo-Date then the file name should be generated like: 001-20170512
if user chooses VendorName-InvoiceNo-Date then the file name should be generated like: ABCElectronics-001-20170512
format.Replace("InvoiceNo",generateNo());
Will .Replace first check if string exists and then executes the 2nd parameter? The 2nd parameter could be a long running method.
Should I first check if tag exists in the file format and then replace or just use .Replace method without checking?
Thanks
simple way:
input = input.Replace("InvoiceNo",generateInvo());
input = input.Replace("Date",generateDate());
input = input.Replace("Vendorname",generateVendor());
this will change the first occurrence of those strings for the code you desire.
You can also do this in one line like x.Replace(y0,y1).Replace(z0,z1); if you wish.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am having file name as below.
i need only sample.xml as result.
sample.xml.jued.783737377365474.da
Please help me on this. thanks in Advance
File name can have one extension only:
string path = "sample.xml.jued.783737377365474.da";
// ".da"
var ext = Path.GetExtension(path);
However, in case you have a origin.extension.[some data].da pattern, you can split the file name by . and take first two items:
// sample.xml
var origin = String.Join(".", Path
.GetFileName(path)
.Split(new char[] { '.' }, 3)
.Take(2));
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have a C# task to do and I am stuck on part of the coding. I am using StreamReader to read a .txt file which contains group exam grade data (e.g. ADCBCBBBADEBCCBADBAACDCCBEDCBACCFEABBCBBBCCEAABCBB), I need the code to work out how many A's, B's etc there are inside each set of data, I thought about using some form of count++ code but each attempt just throws errors.
I want it to print onto console the number of A's in that line of the .txt file.
I hope that makes sense, I understand how to do the rest but I just needed a hand on this section.
Consider using System.Linq, eg...
string myString = "ADCBCBBBADEBCCBADBAACDCCBEDCBACCFEABBCBBBCCEAABCBB";
int countOfAs = myString.Count(x => x == 'A');
//Result: 9