aewarnick Posted February 11, 2003 Posted February 11, 2003 Is there a way that I can put special start and end marks in my text files that I can use to have a stream read in between them? Ex: :TB1S:jglkaj dgjlkajd akjdlg kjdglkaj glajsd:TB1E: Quote C#
Moderators Robby Posted February 11, 2003 Moderators Posted February 11, 2003 Yup. then use Regular Expressions to retrieve them. http://www.xtremedotnettalk.com/search.php?s=&action=showresults&searchid=148079&sortby=lastpost&sortorder=descending Quote Visit...Bassic Software
aewarnick Posted February 11, 2003 Author Posted February 11, 2003 The link was all vb stuff. I need C#. Also, I have no idea what regular expressions are or how to use them. Please direct me somewhere or explain if you can. Quote C#
*Gurus* divil Posted February 11, 2003 *Gurus* Posted February 11, 2003 Why not try Google? There are loads of articles on Regular Expressions online - what they are, how to use them, and using them with the .NET framework. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
aewarnick Posted February 11, 2003 Author Posted February 11, 2003 Ok, I will look and research. Thank you for your help. I will post back with what I learn. Quote C#
Leaders quwiltw Posted February 11, 2003 Leaders Posted February 11, 2003 If you've got the ability to define these start and end markers, why not use xml? Then you don't have to figure out your own parsing logic, just build on what the framework gives you. just a thought. Quote --tim
Moderators Robby Posted February 11, 2003 Moderators Posted February 11, 2003 I was so focused on the question itself that I didn't consider it, as quwiltw mentioned XML is really your best route. Quote Visit...Bassic Software
aewarnick Posted February 11, 2003 Author Posted February 11, 2003 It is too bad I have not learned xml yet. I will have to soon. Quote C#
Heiko Posted February 11, 2003 Posted February 11, 2003 I'd rather start with XML and move to Regular Expressions later. Quote .nerd
aewarnick Posted February 11, 2003 Author Posted February 11, 2003 With xml can I append strings into certain markers in the xml document just as I was going to do with with my text document, except easier? Quote C#
Leaders quwiltw Posted February 11, 2003 Leaders Posted February 11, 2003 The "xml" part of it is the string-based markers your appending. For example, <myFile> <myMarker>jglkaj dgjlkajd akjdlg kjdglkaj glajsd</myMarker> </myFile> Now any node (or marker in your terms) is directly accessible using XPath or you can manually traverse the "tree" Read up: http://msdn.microsoft.com/msdnmag/issues/01/01/xml/default.aspx Quote --tim
aewarnick Posted February 11, 2003 Author Posted February 11, 2003 So, it would be kind of like an array except it is all text. In other words I can reference a certain node from the program and write to and extract data. Right? Quote C#
*Experts* Bucky Posted February 11, 2003 *Experts* Posted February 11, 2003 Yes, or you could Serialize a class to and from XML, and then all you'd need to do is access the class members. Or you could create an XML Schema and then load and save the XML through a DataSet. The possibilities are endless. If you're looking to save and load program settings, or something similar, Serialization is the way to go. Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
aewarnick Posted February 11, 2003 Author Posted February 11, 2003 Runtime Error : Binary Formatter incompatability. Expected version - 1.0, received version - (estemate) 17654837.83746353 this.NewLogB.Enabled=true; NLClosed=0; string file="CommLog\\"+DateTime.Now.ToLongDateString()+".txt"; this.richTextBox1.Clear(); //StreamReader SR=new StreamReader(file); //this.richTextBox1.Text+=SR.ReadToEnd(); string[]holdIt=new string[20]; FileStream FS=new FileStream(file,FileMode.Open); BinaryFormatter BF=new BinaryFormatter(); (this is the problem):::::: holdIt=(string[])BF.Deserialize(FS); FS.Close(); richTextBox2.Clear(); richTextBox1.Text+=holdIt[0]; richTextBox2.Text+=holdIt[1]; What did I do wrong? Quote C#
aewarnick Posted February 12, 2003 Author Posted February 12, 2003 Did I do something wrong? Quote C#
*Experts* Volte Posted February 12, 2003 *Experts* Posted February 12, 2003 If you're serializing to binary, then it won't be a human-readable textfile in the end. Here is an example of serializing to XML: Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim sa() As String = {"Extreme", "Visual", "Basic", "Forum"} Dim ser As New Xml.Serialization.XmlSerializer(GetType(String())) Dim fs As New IO.FileStream( _ Application.StartupPath & "\beh.txt", IO.FileMode.OpenOrCreate) Dim tw As New IO.StreamWriter(fs) Dim tr As New IO.StreamReader(fs) ser.Serialize(tw, sa) Dim dum As String, ret() As String, out As String ret = ser.Deserialize(tr) For Each dum In ret out &= dum & " " Next MessageBox.Show(out.Trim) End SubThere is lots of documentation in the MSDN regarding serialization, when to use it, and how to use it. I would suggest giving it a good once-over. The Xml.Serialization namespace is the key to XML serialization, so check out the docs on it. Quote
aewarnick Posted February 12, 2003 Author Posted February 12, 2003 (edited) That is vb not c# and when I save a string array in binary format I can read what I wrote in between the squares. But even if I couldn't, can't I deserialize it to read it? Remember, these binary text files that I am making are only for use within the application. I would be a bad thing if the user had access to the text files. Then they could edit them. But I should be able to deserialize the text files in my application and read them just as they were written, right? Edited February 12, 2003 by aewarnick Quote C#
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.