Тёмный
No video :(

C# Data Access: Text Files 

IAmTimCorey
Подписаться 417 тыс.
Просмотров 267 тыс.
50% 1

To sign up for announcements about new videos and exclusive discounts, fill out this form: signup.iamtimcorey.com/ (your email will be kept safe and you will not be spammed).
Data access in C# is not really hard, but there is a lot of conflicting information out there. This video will help you clear up how to read from and write to a text file. It doesn't cover every method, just one of the easiest.
0:00 - Intro
0:54 - Creating Demo Console App
1:39 - File path: string literal explained
2:51 - Reading from text file
5:00 - Writing to text file
7:07 - Populate DataModel fields form text file:
9:33 - • Line split
12:20 - • String interpolation
15:24 - Note on data validation when reading form text file
17:45 - Adding object to a list:
18:47 - • Anonymous instance explained
19:45 - List of DataModel to text file
23:22 - Summary and concluding remarks
Thanks Ralfs HBK for the chapter breakdown

Опубликовано:

 

1 авг 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 376   
@juannunez3224
@juannunez3224 4 года назад
Thank you so much. The professor I have never makes us code, He always give us a power point presentation and send us home with a lab. It is nice to see someone who takes the time and explain us the code behind the theory.
@IAmTimCorey
@IAmTimCorey 4 года назад
Glad I could help!
@davidramirez3322
@davidramirez3322 5 лет назад
Can't belive it! 80% of my work is based on text files, move it, make logs about the actions taken, update, read it to valid them, awesome Tim, you get a great way to teach. I am your Fan!! Its pure gold. Thanks so much!
@IAmTimCorey
@IAmTimCorey 5 лет назад
I'm glad this video will be so useful to you.
@regal_7877
@regal_7877 2 года назад
I can't believe how helpful this actually was. I'm actually mind blown by how you managed to convey so much information and clear up a lot of my question so simply. thank you very very much. You're a blessing to humankind
@IAmTimCorey
@IAmTimCorey 2 года назад
Glad it was helpful!
@nothingtosee8381
@nothingtosee8381 2 года назад
EXTREMELY helpful. I have been seating at my laptop for 3 hours trying to find how to read and write from text files to make a log-in interface and nothing helped me, except this beauty. Much appreciated!
@IAmTimCorey
@IAmTimCorey 2 года назад
I am glad it was so helpful.
@RalfsBalodis
@RalfsBalodis 3 года назад
0:00 - Intro 0:54 - Creating Demo Console App 1:39 - File path: string literal explained 2:51 - Reading from text file 5:00 - Writing to text file 7:07 - Populate DataModel fields form text file: 9:33 - • Line split 12:20 - • String interpolation 15:24 - Note on data validation when reading form text file 17:45 - Adding object to a list: 18:47 - • Anonymous instance explained 19:45 - List of DataModel to text file 23:22 - Summary and concluding remarks
@IAmTimCorey
@IAmTimCorey 3 года назад
Thank you kind sir!
@peterjones6733
@peterjones6733 4 года назад
Tim, that was So well explained!!! Just learning C# in past week after VBA. Storing data is key. You’ve shown me how easy this is and also to understand what’s happening. Thank You!!!
@IAmTimCorey
@IAmTimCorey 4 года назад
Glad it was helpful!
@Almethese84
@Almethese84 7 лет назад
Amazing! Informative, clear and useful information! Please continue to make these great videos, I appreciate them and thank you for your time in making them!
@RalfsBalodis
@RalfsBalodis 3 года назад
Reading from and writing to text files has come in very handy to me. Thank you, Tim! :) I've been doing access and security system upgrade at work for a client. Database form old system was not compatible with the new system, although it was the same manufacturer... So only option was to re-configure whole system by hand. Lucky for me, old system had a feature to print out programming as csv files. And new system could take csv in. Only problem was that text files needed to be cleaned up and needed some other work and many manipulations to be usable. Now with C# I've been flying through text files containing thousands of lines like it was nothing. Filtering, rearranging, creating new lists and other stuff. New system was ready in no time. So to speak... These basic techniques has really made my life easier. To give you some kind of reference - we don't use computer programming at work. We work with hardware. Installation and service. Electronics. To use C# at work is like using some kind of space age technology. Very exciting! One may argue, that you could use excel for working with csv... I'd say - excel is limited thou. You can't do stuff with excel like you can with C#. With C# it's freedom. Thank you!
@IAmTimCorey
@IAmTimCorey 3 года назад
Thanks for the tips
@mrf7283
@mrf7283 2 года назад
First of all thanks for refresher. Sometimes if you get lost in c# thing become really complicated than they should be. This is an old video but still so relevant. I just fixed some of my code after watching it. Your video never fail to deliver. I really appreciated your efforts. 👍
@IAmTimCorey
@IAmTimCorey 2 года назад
You are welcome.
@malcolmtucker8611
@malcolmtucker8611 7 лет назад
Tim Great Video. New items make it far clearer.
@jankes11ful
@jankes11ful 7 лет назад
Like the way you explain things. You just got a new subscriber. Definetely will watch more!
@TheAngelOfDeath01
@TheAngelOfDeath01 7 лет назад
Chuckles. Just keep standing on that "soapbox". The Gospel you sing is very informative and good learning! So don't give up on it, mate.
@IAmTimCorey
@IAmTimCorey 7 лет назад
I'll keep preaching good development practices. Don't worry. :-)
@samstanton8655
@samstanton8655 7 лет назад
This was an extremely helpful tutorial! Thank you so much for posting this!
@alandotchin1829
@alandotchin1829 2 года назад
Thanks Tim. Great tutorial, very clear and concise as with the rest of your tutorials. Keep up the good work!
@IAmTimCorey
@IAmTimCorey 2 года назад
You are welcome.
@naderbelal8439
@naderbelal8439 6 лет назад
Thank you alot, that was the type of tutorial that I needed
@IAmTimCorey
@IAmTimCorey 6 лет назад
Excellent!
@mrnhaque
@mrnhaque 4 года назад
I'm struggle to build a "practising app" when learn C#, don't know how to get data to excute and then save back to. Text file absolutely is easy way. Your video help me much. Hope I've learnt more from your database turorial. Thanks.
@IAmTimCorey
@IAmTimCorey 4 года назад
You are welcome.
@shaynemurray6351
@shaynemurray6351 6 лет назад
Thank you , your list of string method is very elegant. List processing has come of age compared to multidimensional arrays, which are fine if your a string theory physicist used to thinking in multi dimensions.
@IAmTimCorey
@IAmTimCorey 6 лет назад
Yep, List is pretty powerful.
@tudi6029
@tudi6029 4 года назад
Thank you! Simple and to the point, thank you very much! I just subscribed just because of this one video.
@IAmTimCorey
@IAmTimCorey 4 года назад
You are most welcome. Thanks for watching.
@fadidib8516
@fadidib8516 2 года назад
thx for the videos, I like that u go in-depth on one particular thing.
@IAmTimCorey
@IAmTimCorey 2 года назад
You are welcome.
@eduardoliveros
@eduardoliveros 7 лет назад
Nice Video Timothy! Thanks
@sallehheyat8980
@sallehheyat8980 5 лет назад
timothy ? :D
@andrewthebladethrower8371
@andrewthebladethrower8371 2 года назад
thank you sir. I spent the whole day manipulating data with jugged arrays, I am giving lists a try.
@IAmTimCorey
@IAmTimCorey 2 года назад
You are welcome.
@gggdrengen
@gggdrengen 5 лет назад
this video helped me alot, very useful, clear and simpel information. Thanks alot Tim :)
@IAmTimCorey
@IAmTimCorey 5 лет назад
Awesome!
@olivierhoule8961
@olivierhoule8961 4 года назад
One of the best tutorials ever!!
@IAmTimCorey
@IAmTimCorey 4 года назад
Thank you!
@nanakomastu4354
@nanakomastu4354 4 года назад
Thank u so much sir for making concepts this much simple and effective... i appreciate ur effort for these tutorials...
@IAmTimCorey
@IAmTimCorey 4 года назад
You are welcome.
@brightndiweni1657
@brightndiweni1657 6 лет назад
Awesome and clean explanations especially for us beginners, wish to see more tutorial on delegates, reflection, dependency injection, rest services, more in-depth on unit testing, web api and asp.net mvc
@IAmTimCorey
@IAmTimCorey 6 лет назад
I appreciate the suggestions. Unit testing videos will be coming soon, along with dependency injection for sure. The others are coming, just further back.
@FerreusDeus
@FerreusDeus 3 года назад
That is the easiest and clearest I have ever seen that explained.
@IAmTimCorey
@IAmTimCorey 3 года назад
Thanks.
@marinosanagnostou8116
@marinosanagnostou8116 7 лет назад
Very good, professional work. Thank you for your effort. Please, continue .....
@IAmTimCorey
@IAmTimCorey 7 лет назад
Will do.
@danvalrub
@danvalrub 6 лет назад
Awesome video, very clear for a non-native english speaker.
@IAmTimCorey
@IAmTimCorey 6 лет назад
Excellent!
@Furki4_4
@Furki4_4 2 года назад
Thank you Tim, love your exposition
@IAmTimCorey
@IAmTimCorey 2 года назад
You are welcome.
@tommyle4648
@tommyle4648 4 года назад
Thank you, I liked and subscribed to your channel! just what I needed to expand my knowledge
@IAmTimCorey
@IAmTimCorey 4 года назад
You are welcome.
@ThemLowkeyyBeats1
@ThemLowkeyyBeats1 4 года назад
Wow, you really know what you're doing. Great tutorial!
@IAmTimCorey
@IAmTimCorey 4 года назад
Thank you!
@roccos9279
@roccos9279 7 лет назад
Great video Timothy! You make it so easy to understand.if you can...Could you please make a video on how to validate data in a List?Like how would you check if a new Person you are trying to add is already on the List?Thank you
@Michael-oi5fl
@Michael-oi5fl 4 года назад
You are a godsend, sir. I love your videos. The 18 people that thumbs downed should be ashamed of themselves.
@IAmTimCorey
@IAmTimCorey 4 года назад
Thank you!
@wisbenah
@wisbenah 7 лет назад
Thanks for the video... Nice presentation.
@jamescaleb9676
@jamescaleb9676 6 месяцев назад
Finally a programmer with common sense who can teach! Thanks!
@IAmTimCorey
@IAmTimCorey 5 месяцев назад
You are welcome.
@samuelbjorkqvist2282
@samuelbjorkqvist2282 4 года назад
So exceptionally great! Thanks for all your awesome videos! :D
@IAmTimCorey
@IAmTimCorey 4 года назад
You are most welcome. Thanks for watching.
@ThrashAbaddon
@ThrashAbaddon 7 лет назад
thank you :)
@prabodamperera8049
@prabodamperera8049 6 лет назад
great one.I love the way you are explaining things.Thanks
@IAmTimCorey
@IAmTimCorey 6 лет назад
You are welcome.
@prabodamperera8049
@prabodamperera8049 6 лет назад
I tried to implement the method to asp.net text box.But it's not working
@plinioferreiradasilvaneto5471
@plinioferreiradasilvaneto5471 4 года назад
Amazing content. Thank you!
@IAmTimCorey
@IAmTimCorey 4 года назад
Thank you!
@christopher_zhong
@christopher_zhong 7 лет назад
Great video. If you can add more error handling checking, it is very helpful. Thank you!
@IAmTimCorey
@IAmTimCorey 7 лет назад
When demoing a specific topic, I try to stick to that topic specifically. Otherwise it can become overwhelming to the viewer and confusing as to what is "other code" and what is code specific to the topic. I'll be doing a video specifically about error handling in the near future though.
@hadeseye2297
@hadeseye2297 6 лет назад
Very informative. Thanks.
@IAmTimCorey
@IAmTimCorey 6 лет назад
You are welcome.
@TonyDaExpert
@TonyDaExpert 3 года назад
This is what I needed thanks!
@IAmTimCorey
@IAmTimCorey 3 года назад
Glad I could help!
@user-ob7ix9fd7u
@user-ob7ix9fd7u 3 года назад
Thank you! Very helpful tutorial
@IAmTimCorey
@IAmTimCorey 3 года назад
Glad it was helpful!
@vacston
@vacston 4 года назад
You my sir are a life saver thanks :)
@IAmTimCorey
@IAmTimCorey 4 года назад
You are welcome.
@automatykarobotyka2333
@automatykarobotyka2333 4 года назад
Great video, clear explain.
@IAmTimCorey
@IAmTimCorey 4 года назад
Thank you!
@sleepymarauder4178
@sleepymarauder4178 5 лет назад
Clear explanation. Subbed
@IAmTimCorey
@IAmTimCorey 5 лет назад
Thanks!
@ariellopezcavazos472
@ariellopezcavazos472 3 года назад
Great tutorial !!. Thank you so much Sr.
@IAmTimCorey
@IAmTimCorey 3 года назад
You are welcome!
@mdgobaten2120
@mdgobaten2120 6 лет назад
Hi, Thanks for this video .
@IAmTimCorey
@IAmTimCorey 6 лет назад
You are welcome.
@sebastiantomczak7184
@sebastiantomczak7184 6 лет назад
Wow! Nice, thanks a lot!
@IAmTimCorey
@IAmTimCorey 6 лет назад
You are welcome.
@nawfelhamdi1551
@nawfelhamdi1551 Год назад
Thank You Tim for all your content, please can you create a tutorial about XML Serialization and Deserialization in C#
@IAmTimCorey
@IAmTimCorey Год назад
Thanks for the suggestion. Please add it to the list on the suggestion site so others can vote on it as well: suggestions.iamtimcorey.com/
@exogendesign4582
@exogendesign4582 3 года назад
Damn, so its called spring interpolation now everything popped up on google, these keyword are really tricky. Thanks for the tutorial.
@IAmTimCorey
@IAmTimCorey 3 года назад
I am glad it was helpful.
@ZeroSleap
@ZeroSleap 4 года назад
Wow didnt know about interpolated strings ($"") being faster than " "+"..." Etc.This i will use in the future even for convenience and perfrmance gain.Thanks!
@IAmTimCorey
@IAmTimCorey 4 года назад
It is faster to type and read. Performance-wise, it is equivalent. Sorry for the confusion.
@theresaposey
@theresaposey 4 года назад
awesome teacher thank u
@IAmTimCorey
@IAmTimCorey 4 года назад
You are welcome.
@barnabask5321
@barnabask5321 4 года назад
ty i studied a lot
@IAmTimCorey
@IAmTimCorey 4 года назад
Great!
@chode1815
@chode1815 5 лет назад
thx SO much for this, big ups to yourself
@IAmTimCorey
@IAmTimCorey 5 лет назад
You are welcome.
@scientist100
@scientist100 4 года назад
I believe this is what Facebook used to store plain text passwords. They probably watched your video and thought, "Hey, we can save time by not hashing password in a database, it will be quick." Brilliant.
@IAmTimCorey
@IAmTimCorey 4 года назад
No, Facebook doesn't store clear-text passwords.
@scientist100
@scientist100 4 года назад
@@IAmTimCorey You didn't read about it? www.theverge.com/2019/3/21/18275837/facebook-plain-text-password-storage-hundreds-millions-users
@IAmTimCorey
@IAmTimCorey 4 года назад
So that wasn't about passwords in a database. What happened was that they had a logging system that logged when certain actions happened (common). One of the log actions captured a user's password (I believe it was when it was changed but I can't remember exactly). That log was in plain text so the user's password was in it if you looked for it. They weren't storing the user's password in plain text. That was encrypted. Their logs, though, weren't. That's why security is more than just about a password or SSL. You have to think about every step along the way.
@mazenas3443
@mazenas3443 4 года назад
U R Amazing man ,thank u from Idlib and wish u be in All Fine thinks because U R Powerfull Teacher
@IAmTimCorey
@IAmTimCorey 4 года назад
I appreciate the kind words.
@mazenas3443
@mazenas3443 4 года назад
@@IAmTimCorey can u make video About sending Files to Email by C# ?
@block1364
@block1364 6 лет назад
Thx, good video helpful.
@IAmTimCorey
@IAmTimCorey 6 лет назад
You are welcome.
@christianrodier3381
@christianrodier3381 4 года назад
That was very helpful
@IAmTimCorey
@IAmTimCorey 4 года назад
Excellent!
@Evan-zj5mt
@Evan-zj5mt 6 лет назад
Hey Tim, love your videos. They've really helped me get information in and out of a file. One thing I'm unsure of though, is how to do you overwrite data after variables have been changed during an apps use? Would it just be a case of clearing the file before you save your data again?
@IAmTimCorey
@IAmTimCorey 6 лет назад
The version of the save I am using overwrites the text file instead of appending to it. You can change that, though, if you want to append instead of overwriting.
@Evan-zj5mt
@Evan-zj5mt 6 лет назад
Wow, quick reply. Thanks, Tim.
@Rangieh
@Rangieh 5 лет назад
This is nice, very informative... Thanks Tim... I just want to know if one entries has comma character, what happen if I use comma as delimeter...
@IAmTimCorey
@IAmTimCorey 5 лет назад
Things break. You have a couple options then. First, you could strip out commas before you insert the values into the text file (in case they aren't needed), you could change the delimiter (pipe is almost never used in normal typing or you could use a double character like two pipes), or you could account for it using double quotes. That last one is a bit trickier because you have to change how the split works. You would manually split the records but if you encountered a ," combination, you would not split on the next comma until after you saw the end double-quote symbol. This is how "real" csv files work.
@ericsimpson4513
@ericsimpson4513 5 лет назад
Great video. Is this the same as serialization? It would be great if you could do a video on XML, JSON, and other types of serialization. Also, how to read and apply a configuration file. Keep up the great work!
@IAmTimCorey
@IAmTimCorey 5 лет назад
Not quite the same as serialization but close. More semantics than anything. Thanks for the suggestions.
@TonyPepperoni27
@TonyPepperoni27 4 года назад
great vid!!
@IAmTimCorey
@IAmTimCorey 4 года назад
Thank you!
@mcdaddy1334
@mcdaddy1334 4 года назад
VERY NICE!
@IAmTimCorey
@IAmTimCorey 4 года назад
Thank you!
@caedriel5555
@caedriel5555 7 лет назад
I found this tutorial pretty helpfull . In the last 3 years of me coding , i have not been able to make a High score system in the games i have worked on =)
@IAmTimCorey
@IAmTimCorey 7 лет назад
Well, there you go. Now you can save your high scores.
@caedriel5555
@caedriel5555 7 лет назад
Thanks ! can you possibly upload code files with comments ? this would really help the people who watch your videos .
@IAmTimCorey
@IAmTimCorey 7 лет назад
Depending on the video, I do post the code but usually the code is small enough that you can follow along and re-create it for yourself. That has the added benefit of increasing your learning while providing you the code.
@caedriel5555
@caedriel5555 7 лет назад
IAmTimCorey I totally agree with you there. For me I prefer to download videos & re watch them .
@MrGL4455
@MrGL4455 6 лет назад
Thank you very much!!
@IAmTimCorey
@IAmTimCorey 6 лет назад
You are welcome.
@MrGL4455
@MrGL4455 6 лет назад
hi please help i want to skip row or word in my csv file i want to use "if" decision statement
@stephencarroll4171
@stephencarroll4171 Год назад
Old video but to a an old programmer updating my skills it's gold. It re-writes the file each time. Thinking of huge text files 500MB to 1GB it would probably take forever to save. Thinking of changing it to only update the changed lines, what would you recommend I research C# wise?
@meirsdag3581
@meirsdag3581 Год назад
Thank you!
@IAmTimCorey
@IAmTimCorey Год назад
You're welcome!
@chetanbehl388
@chetanbehl388 4 года назад
Thnx sir. Your teaching methods good. Please create a video on firebird database connectivity with c sharp
@IAmTimCorey
@IAmTimCorey 4 года назад
I will add it to the list. Thanks for the suggestion.
@SingCor1
@SingCor1 5 лет назад
Finally it worked! Thank you!!!
@IAmTimCorey
@IAmTimCorey 5 лет назад
Great!
@gazzolapw
@gazzolapw 3 года назад
Awesome vidio thank so much. But how do I search for specific line(person) then remove it? Thank u so much
@ZiaurRahmanAdvocate
@ZiaurRahmanAdvocate 4 года назад
good presentation
@IAmTimCorey
@IAmTimCorey 4 года назад
Thank you!
@RiteshSookun
@RiteshSookun 5 лет назад
Hi, nice video. Just a quick question - is there a way to print to the console only one list item (eg. line 9 in the FirstName list)?
@IAmTimCorey
@IAmTimCorey 5 лет назад
I'm not sure I understand the question. Yes, you get to choose what you print to the console. You can print just one object or even just one part of one object to the console.
@EwRecK1986
@EwRecK1986 7 месяцев назад
So what is the benefit or difference of using FIle.ReadAllLines, File.WriteAllLines compared to using StreamReader, StreamWriter?
@AlexSandro-tr3ci
@AlexSandro-tr3ci 4 года назад
Just awesome
@IAmTimCorey
@IAmTimCorey 4 года назад
Thank you!
@stanleypaseur2553
@stanleypaseur2553 3 года назад
very useful. However my output file will be hundreds of lines long. Reading it in as a list, adding one line and then writing it out will take up too much time. I need to just append/add to the file by adding a new line. Any thoughts?
@kyledawg92
@kyledawg92 3 года назад
How would you access just one variable out of the object? Like say I wanted the last name of the third person?
@newbeezz
@newbeezz 5 лет назад
thank you very muchhhh
@IAmTimCorey
@IAmTimCorey 4 года назад
You are welcome.
@shayg6072
@shayg6072 6 лет назад
First of all, Thank you VERY much for your free, comprehensive videos!! I cant say how much they have helped me. I have a question that have been researching and could not find the answer for it. I have a program that generates a text file and I want to create report based on that text file. I have found Microsoft report viewer but I am not sure how to use it with my text file. I dont want to pass the whole text file to the report viewer, rather pass some parts of it and create a table out of it in my report. I would greatly appreciate any help.
@IAmTimCorey
@IAmTimCorey 6 лет назад
It sounds like you should create a second text file that is the one you run through report viewer so that you don't have to worry about reporting on the whole thing. As for creating a table out of the data, that's something you will have to play around with. Maybe create a CSV file and have report viewer parse it?
@shayg6072
@shayg6072 6 лет назад
Thank you very much for your quick reply. Can I pass images to report viewer as well. Is there a tutorial on how to do that? Since I want to pass some images as well as the text file combined together.
@henrik3098
@henrik3098 Год назад
thanks dude
@IAmTimCorey
@IAmTimCorey Год назад
You are welcome.
@novaplum1617
@novaplum1617 5 лет назад
No matter where I place the file, and write the file path EXACTLY as i have it structured, the compiler will not find the file and runs an exception. I cant seem to find anything about how to fix this online. EDIT: Pretty sure that it was reading the file "Test.txt" as "Test.txt.txt". When i removed the ".txt" part of the file name, the program compiled normally. I found that solution on stackoverflow and it helped out. Anyways, it was a naming problem on my end. Sorry for the mix up and thanks for the tutorials :)
@IAmTimCorey
@IAmTimCorey 5 лет назад
Glad you figured it out.
@theshubhagrwl
@theshubhagrwl 6 лет назад
Cool thing. Thanks
@IAmTimCorey
@IAmTimCorey 6 лет назад
You are welcome.
@gregsonnawahin6251
@gregsonnawahin6251 3 года назад
very impressive and outstanding explanation Can i ask is this can be used as data base from that text file?
@IAmTimCorey
@IAmTimCorey 3 года назад
You could use this in place of a full database if it is a small enough application. If it gets too big, it would be too fragile.
@Blackener
@Blackener 5 лет назад
"Assuming is the mother of all problems when it comes to programming" -The best quote of all times
@IAmTimCorey
@IAmTimCorey 5 лет назад
It is one of Tim’s Software Development Commandments. The next is “Don’t trust the user”.
@christophfrenzel6859
@christophfrenzel6859 4 года назад
Hey Tim, what's the difference between using a streamwriter/reader or just simply using File.(...) ? Both can achieve the same thing. And thanks for the videos, great help!
@IAmTimCorey
@IAmTimCorey 4 года назад
Depends which type of method you are using with File but it can just be simplicity.
@BoilermakerRV
@BoilermakerRV 3 года назад
I'm curious what you would recommend if one wanted their application to save individual files in the same manner as Excel with .xlsx, Word with .docx or Acrobat with .pdf. I believe some of these formats are simply XML documents, which is just a fancy text file, is it not? I'm currently looking at using JSON to create my "own" file format. Wondering if you have thoughts and/or suggestions for this approach. As always, thanks!
@IAmTimCorey
@IAmTimCorey 3 года назад
I would recommend using a tool to build those formats. You technically could create them but it would be a LOT of work. Writing to the file is the simple part. Knowing what to write is the hard part.
@emaus8344
@emaus8344 2 года назад
Hello, what is the best way to extract text from PDF or Docx files?
@bradfeigenbaum5227
@bradfeigenbaum5227 5 лет назад
Hi Tim, what if two fields in the text file are numbers and you wanted to calculate the sum of the two numbers in a new field then output that into the same text file?
@IAmTimCorey
@IAmTimCorey 5 лет назад
I'm not sure what the question is. Yes, you can do that. You just need to build the logic to do so.
@rayt6867
@rayt6867 5 лет назад
Have you used TextFieldParser in the Microsoft.VisualBasic.FileIO namespace? Also there is CsvHelper NuGet package. Thanks for your videos.
@IAmTimCorey
@IAmTimCorey 5 лет назад
Nope to either. The TextFieldParser seems to be rather full-featured. I prefer to do the work directly, especially since this is about learning to work with strings and the text file. Good find, though.
@boost5207
@boost5207 2 года назад
I have a question. If i wanted to access, for example, greg jones lastname, and change it to a new lastname, or for that matter any variable, how would i achieve that? As far as i know, list have index to access, but can i make it so, that all person also has ID variable, that is stored in the text file, and use that ID to get all the content of that particular line, and then do stuff with that line person information. Hope it makes sense.
@IAmTimCorey
@IAmTimCorey 2 года назад
Text files cannot be used like databases. You would need to read in the file, make the change, and then write those changes back to the file. The easiest way is to read the whole file and then overwrite the whole file with the new data.
@esewiegheosa1694
@esewiegheosa1694 5 лет назад
Very informative video helped me out a lot, but I have a question. Is there a way to pass text from the file into a 2D array. so each comma represents a column, and line represents a row to make up a table. i.E mammals, Dogs, cats, horses, Platypus Fish, Clownfish, Salmon, Crayfish, Tuna Birds, Parrots, Pigeons, Sparrows, Penquin The point is to make an easy way to randomly choose a category and then display the elements within it.
@IAmTimCorey
@IAmTimCorey 5 лет назад
Once you read the text in, you can put it into any structure you want.
@bjornkreye2211
@bjornkreye2211 6 лет назад
Hi awesome video helped me a lot already but how do i handle the problem, when i only know what my 5 first columns are and after that i can have unlimited more columns? So i know my first couple columns are name, last name, street, etc. and after that i get for every file i want to load a different amount of columns that i dont know anything about.
@IAmTimCorey
@IAmTimCorey 6 лет назад
Not a problem. Since you read each line in as a full line and then split on the separator (usually the comma), you can have as many columns as you want. You probably cannot create class properties for each column but you can have an array property that handles all of the "extra" columns.
@pauljekyll3508
@pauljekyll3508 4 года назад
When creating csv files, do I need to avoid strings that have a comma in them? Or is there a trick to it?
@IAmTimCorey
@IAmTimCorey 4 года назад
Avoiding commas is the easiest thing to do. Another option is to change the delimiter from comma to something even less used like a pipe character (|). You can also escape the comma by changing it to a different value and then changing it back. The official CSV format allows commas by putting strings inside quotes but this makes it a bit more difficult to work with in C# without a library.
@AdrianRoix
@AdrianRoix Год назад
Hi Tim, Thank you for your videos. What happens when a new object is created in a for/foreach loop? Is the first object reused? If not, then on a larger scale could creating objects in for/foreach loops produce clutter in the program, and what could be done to avoid that? The first thing I think of is creating a placeholder instance of an object outside of a loop that the can be accessed, using it to hold temporary values. It also dawned on me to possibly add a number at the end of each instance being created within the loop so each instance has a unique name. Am I over thinking this? I would like to know how this is functioning on as low-level as I can.
@IAmTimCorey
@IAmTimCorey Год назад
In a foreach loop, the variable is getting re-initialized in every iteration. The old data is discarded and the garbage collector will clean it up. However, if you are iterating over objects (like class instances), you aren't actually duplicating the class, just the location of the class (super-efficient). No, there is rarely a case where you need to optimize a foreach loop because of the variable. I can't remember an instance where I've needed to do that. The placeholder wouldn't solve anything because it would end up doing the same exact work. Adding a number to the variable name? No, you couldn't do that and it wouldn't be valuable to do. In fact, it would be terribly inefficient. The variable only lives for one iteration of the loop. In your mechanism, it would actually last longer (in theory).
@AdrianRoix
@AdrianRoix Год назад
@@IAmTimCorey I came across the term garbage collector somewhere but I haven't really thought I should look into it until now. I appreciate you clearing up some of my speculation (though there will always be more) with your response. Thank you for your time and service. Subscribed!
@geon-younghong7832
@geon-younghong7832 5 лет назад
Hello, Tim. this video's really helpful to me. By the way, I used to used StreamWriter and StreamReader to handle text data. ( with using keyword). is there difference between File class and StreamWriter class? Thank u in advance.
@IAmTimCorey
@IAmTimCorey 5 лет назад
That's fine. The difference is more in the wrapping. The File class opens the text file, writes all of the data, and properly closes the connection. The StreamWriter allows you to control those actions. The key is to make sure you properly close the connections.
@geon-younghong7832
@geon-younghong7832 5 лет назад
@@IAmTimCoreyThanks Tim!
@JoshyHJoshy
@JoshyHJoshy 7 лет назад
Dear Timothy, I had to use the following syntax for displaying people using foreach loop, since my VS2010 does not support the $ format: Console.WriteLine( "{0} {1} {2}", person.FirstName, person.LastName, person.URL ); However, trying to use the same format for writing the fields back to the file as a single string confuses me: output.Add( "{0},{1},{2}", person.FirstName, person.LastName, person.URL ); This doesn't work, as Add takes one argument, and not four. output.Add("{person.FirstName},{person.LastName},{person.URL}"); This doesn't work either, as the same literal strings get written back to the file. I wonder if you could please help me figure out what to do here? Thanks
@JoshyHJoshy
@JoshyHJoshy 7 лет назад
Thank you very much indeed.
@captainpotatord6984
@captainpotatord6984 2 месяца назад
im a tad bit confused, when using file.WriteAllLines(FilePath, output); shouldnt it write all of the other person instances instead of just writting another greg
@IAmTimCorey
@IAmTimCorey 2 месяца назад
We do, but we are overwriting the existing file, which means the file looks like we just added another Greg, when in reality we wiped out everything, rewrote everything, and added an additional entry.
@adithyakiransekar
@adithyakiransekar 3 года назад
Hi Tim! ReadAllLines is not useful if it is a huge file, and we probably need to read it in chunks with an open connection. Can you make a video on that?
@tomthelestaff-iamtimcorey7597
@tomthelestaff-iamtimcorey7597 3 года назад
I added this to Tim's list of viewer suggestions for future videos. Thanks for sharing.
@galerians3
@galerians3 5 лет назад
Hello, Tim! First of all, thank you for this video, it really helped me out a lot on a project i'm working on. I have a question though. I want to be able to search for the first element in the file and have the program return the rest of the line to me. Here is an example - Die: 747 measurement: 266.7 Notes: Some sample note here. Something like this but I want to search by die, in other words, the first element. Thanks in advance. Best of luck to you.
@IAmTimCorey
@IAmTimCorey 5 лет назад
Load all of the lines into an array and then just do a search on each one for the starter text.
@galerians3
@galerians3 5 лет назад
@@IAmTimCorey Ok, thank you. I'll try that. I'm also having a really hard time using this code in a try catch block and at the same time creating the file. Any suggestions?
@bonjonbovi-
@bonjonbovi- 2 года назад
can I also access one line? for example FirstName from line 2?
Далее
🌊🌊🌊
01:01
Просмотров 924 тыс.
Best exercises to lose weight ! 😱
00:19
Просмотров 12 млн
how Google writes gorgeous C++
7:40
Просмотров 835 тыс.
C# Read and Write to a Text File
7:09
Просмотров 119 тыс.
How to Load a CSV File to a DataGrid in WPF
15:32
Просмотров 2,3 тыс.
If __name__ == "__main__" for Python Developers
8:47
Просмотров 391 тыс.
Read and Write files in 10 minutes | C#
9:26
Просмотров 36 тыс.