Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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:

C#
  • Leaders
Posted
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.
--tim
  • *Experts*
Posted

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.

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

Posted

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?

C#
  • *Experts*
Posted

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 Sub

There 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.

Posted (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 by aewarnick
C#

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...