well jason i got the Blue file to string, but the problem now is getting it from string. the string will contain unicode and XML dont support that(stupid thing) so i try string splitting but it fail because since the file is embed as bytes the file can contain ANY char, and it is encrypted as bytes again.
please help, this project is getting old and rusty
Need an example :/
below if your to String Function, but After getting tostring, i cant get it From String because XML got problems so is they a way to get out <FILE> by it self because putting it into XDocument.Parse or do i have to use a new function?
[highlight=vb.net]Public Overrides Function ToString() As String
Dim thisName As String = String.Concat("<Name>", Me.Name, "</Name>")
Dim thisCreator As String = String.Concat("<Creator>", Me.Creator, "</Creator>")
Dim thisExtension As String = String.Concat("<Extension>", Me.EXT, "</Extension>")
Dim thisBytes As String = String.Concat("<File>", Encoding.Unicode.GetString(Me.File), "</File>")
Dim output As String = String.Join(ControlChars.Lf, New String() {"<root>", thisName, thisCreator, thisExtension, thisBytes, "</root>"})
Return output
End Function [/highlight]
Posts 1–14 of 14 · Page 1 of 1
Post a Reply
Tags for this Thread
None
Originally Posted by topblast
below if your to String Function, but After getting tostring, i cant get it From String because XML got problems so is they a way to get out <FILE> by it self because putting it into XDocument.Parse or do i have to use a new function?
[highlight=vb.net]Public Overrides Function ToString() As String
Dim thisName As String = String.Concat("<Name>", Me.Name, "</Name>")
Dim thisCreator As String = String.Concat("<Creator>", Me.Creator, "</Creator>")
Dim thisExtension As String = String.Concat("<Extension>", Me.EXT, "</Extension>")
Dim thisBytes As String = String.Concat("<File>", String.Join(" ", Array.ConvertAll(Me.File, Function(b As Byte) b.ToString)), "</File>")
Dim output As String = String.Join(ControlChars.Lf, New String() {"<root>", thisName, thisCreator, thisExtension, thisBytes, "</root>"})
Return output
End Function [/highlight]
So, you're trying to parse the "ToString()" result back into a YourClass?
Originally Posted by Jason
So, you're trying to parse the "ToString()" result back into a YourClass?
Yes
...........
[highlight=vb.net]
Public Overrides Function ToString() As String
Dim root As New XElement("root")
root.Add(New XElement("name", Me.Name))
root.Add(New XElement("creator", Me.Creator))
root.Add(New XElement("extension", Me.EXT))
root.Add(New XElement("file", String.Join(",", Array.ConvertAll(Me.File, Function(b As Byte) b.ToString("X2")))))
Return root.ToString()
End Function
Public Shared Function TryParse(ByVal obj As String, ByRef destination As TClass) As Boolean
Dim parseSuccess As Boolean = False
Try
Dim parsedDoc As XElement = XElement.Parse(obj)
destination.Name = parsedDoc...<name>(0).Value
destination.EXT = parsedDoc...<extension>(0).Value
destination.File = Array.ConvertAll(parsedDoc...<file>(0).Value.Split (New Char() {","c}), Function(s As String) Byte.Parse(s))
destination.Creator = parsedDoc...<creator>(0).Value
parseSuccess = True
Catch ex As Xml.XmlException
parseSuccess = False
Catch nullRef As *********enceException
destination = New TClass() 'clear the input class of any possible values that the failed function added.
parseSuccess = False
Catch format As FormatException
destination = New TClass
parseSuccess = False
End Try
Return parseSuccess
End Function
[/highlight]
Okay, you'll need to change TClass to the classname of whatever your class is called first, and put both those methods within the class.
To use it is simple as a pimple.
[highlight=vb.net]
Dim originalClass As New TClass("jason", "says", ".extension", New Byte() {1, 2, 3, 4}) '//my constructor was name, creator, extension, file...
Dim classString As String = originalClass.ToString() '//now the class is a string, yay. time to parse it back.
Dim newClass As New TClass() '//empty shell to hold the new class.
If TClass.TryParse(classString, newClass) Then
MsgBox("Successful parse is successful")
Else
MsgBox("FUCK YOU JASON SMELLY BUMHOLE")
End If
[/highlight]
Originally Posted by Jason
[highlight=vb.net]
Public Overrides Function ToString() As String
Dim root As New XElement("root")
root.Add(New XElement("name", Me.Name))
root.Add(New XElement("creator", Me.Creator))
root.Add(New XElement("extension", Me.EXT))
root.Add(New XElement("file", String.Join(",", Array.ConvertAll(Me.File, Function(b As Byte) b.ToString("X2")))))
Return root.ToString()
End Function
Public Shared Function TryParse(ByVal obj As String, ByRef destination As TClass) As Boolean
Dim parseSuccess As Boolean = False
Try
Dim parsedDoc As XElement = XElement.Parse(obj)
destination.Name = parsedDoc...<name>(0).Value
destination.EXT = parsedDoc...<extension>(0).Value
destination.File = Array.ConvertAll(parsedDoc...<file>(0).Value.Split (New Char() {","c}), Function(s As String) Byte.Parse(s))
destination.Creator = parsedDoc...<creator>(0).Value
parseSuccess = True
Catch ex As Xml.XmlException
parseSuccess = False
Catch nullRef As *********enceException
destination = New TClass() 'clear the input class of any possible values that the failed function added.
parseSuccess = False
Catch format As FormatException
destination = New TClass
parseSuccess = False
End Try
Return parseSuccess
End Function
[/highlight]
Okay, you'll need to change TClass to the classname of whatever your class is called first, and put both those methods within the class.
To use it is simple as a pimple.
[highlight=vb.net]
Dim originalClass As New TClass("jason", "says", ".extension", New Byte() {1, 2, 3, 4}) '//my constructor was name, creator, extension, file...
Dim classString As String = originalClass.ToString() '//now the class is a string, yay. time to parse it back.
Dim newClass As New TClass() '//empty shell to hold the new class.
If TClass.TryParse(classString, newClass) Then
MsgBox("Successful parse is successful")
Else
MsgBox("FUCK YOU JASON SMELLY BUMHOLE")
End If
[/highlight]
Jason , thanks;hmm the To byte string makes it very big
String.Join(",", Array.ConvertAll(Me.File, Function(b As Byte) b.ToString("X2")))
can i replace that with
Encoding.Unicode.GetString(Me.File) without getting error?
Originally Posted by topblast
Jason , thanks;hmm the To byte string makes it very big
String.Join(",", Array.ConvertAll(Me.File, Function(b As Byte) b.ToString("X2")))
can i replace that with
Encoding.Unicode.GetString(Me.File) without getting error?
Sure, as long as you use Encoding.Unicode.GetBytes on the TryParse method.
Originally Posted by Jason
Sure, as long as you use Encoding.Unicode.GetBytes on the TryParse method.
testing right now
Originally Posted by topblast
testing right now
KK, let me know. I only did a real basic test.
[highlight=vb.net]
Dim nClass As New TClass("jason", "hi", ".cool", New Byte() {1, 2, 3, 4})
Dim wrapper As TClass = New TClass()
If TClass.TryParse(nClass.ToString, wrapper) Then
MsgBox("successful parse!")
MsgBox(wrapper.Creator)
Else
MsgBox("unsuccessful!")
[/highlight]
And it worked .
My test failed in file to string.
error at "Return root.ToString()"
i dont need xml i just want a small string that works
Originally Posted by topblast
My test failed in file to string.
error at "Return root.ToString()"
i dont need xml i just want a small string that works
Saying "I got an error" doesn't exactly help. Exception thrown? If so, what was it? Details ><
EDIT: Just use my method, don't use the Unicode shit, it's the cause of the problem.
Originally Posted by Jason
Saying "I got an error" doesn't exactly help. Exception thrown? If so, what was it? Details ><
EDIT: Just use my method, don't use the Unicode shit, it's the cause of the problem.
from toString this Class going into a File. And for each char in the string thats a byte, making the file much bigger than it needs to be.
so instead of getting a ' ' i have a ',20' which is 3bytes and they can go range from 2bytes{ ',0' } to 4 bytes {',255'}.
i wanted small files because people are picky with memory
Originally Posted by topblast
from toString this Class going into a File. And for each char in the string thats a byte, making the file much bigger than it needs to be.
so instead of getting a ' ' i have a ',20' which is 3bytes and they can go range from 2bytes{ ',0' } to 4 bytes {',255'}.
i wanted small files because people are picky with memory
Well, using Encoding to get the string isn't the best way. Browse for a free compression library to compress the bytes down or something. Encoding.GetString fucks up a lot.