C# file path delimiter




















Tim Tim I am able to add a delimiter in my text which I have tried but I then get an error when I try to run it. I've tried the delimiter, " " by adding that in my row. Split ' ' and adding it to the end of every line and the error I got was that the special. ToDateTime columns[1] ; was not a valid DateTime. JaeChang - the delimiter should go between each field, not at the end of the line. For example: 1 PM As for the not a valid DateTime error, I'm not sure why you got that If you split on the and the ' ', then yes, you would get an invalid DateTime format error because columns[1] would equal "PM".

I really appreciate all your help and options. I'm a newbie and have not learned anything besides classes that work with text files. I will try to go off your comment on my delimiter being between each field.

Thank you Tim! You're welcome. Don't forget to put all the fields on one line in other words, one line per event.

I'll stick another example in my answer for you. Add a comment. ToInt32 lines[index - 4] ; special. ToDateTime lines[index - 3] ; special. ToDouble lines[index - 2] ; special. Tobias Schulte Tobias Schulte 5 5 silver badges 15 15 bronze badges. Hadn't thought of using a for loop that way - I wonder which would be more efficient, the while loop or the for loop? Tim In terms of performance it doesn't matter whether you you use a while loop or a for loop in most cases.

One exception is when you loop through an array and use the "Length" field in the loop-condition in a for loop in this case range checks on array access in the body are omitted, see link. But I don't know if that is true for access to the array like I do here. Tobias Could you explain your given example? Why does it increment by 5? I would like to have the 1st 5 rows as one object, the 2nd 5 rows as another object etc so I can have it populate in a textbox depending on user input.

Jae The basic idea is, that the body of the for loop is executed once for every Event in the file. So it has to read 5 lines in each iteration and therefore increment the index which represents the current line by 5. WriteLine item. Id ; Console. Disclaimer: I'm the author of this library. Cinchoo Cinchoo 5, 2 2 gold badges 16 16 silver badges 32 32 bronze badges. Sign up or log in Sign up using Google. Sign up using Facebook.

Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Podcast Making Agile work for data science. Stack Gives Back Featured on Meta. New post summary designs on greatest hits now, everywhere else eventually. Linked 4. Related Hot Network Questions. Question feed. Stack Overflow works best with JavaScript enabled. Accept all cookies Customize settings.

Use string concatenation to dynamically retrieve the path separator character at runtime and incorporate it into file system paths. For example,. You can also retrieve the value from the AltDirectorySeparatorChar property, since it is the same on both Windows and Unix-based systems.

Retrieve the AltDirectorySeparatorChar property. If your application is not cross-platform, you can use the separator appropriate for your system. Viewed k times. I have a cursor file in project.

I have given the absolute path in code i. Improve this question. Richard Ev Have you tried to pack r. David yes i Have tried this by putting the r. This might seems okay. Show 6 more comments. Active Oldest Votes. GetCurrentDirectory ; So you can use the following to get the directory path of the application executable: System. ExecutablePath ;. Improve this answer. Pavel Cermak Pavel Cermak 1, 9 9 silver badges 13 13 bronze badges. The above code dosen't work in WPF as as it not have System.

Forms namespace.



0コメント

  • 1000 / 1000