Covert a String to a TextStream?

BlitzMax Forums/BlitzMax Programming/Covert a String to a TextStream?

ziggy(Posted 2007) [#1]
that's it, any idea if there's an easy and fast way to do this?


marksibly(Posted 2007) [#2]
Hi,

Not currently - what's really needed is a TStringStream. May have a go at this today.


ziggy(Posted 2007) [#3]
I've managed to make it this way:
Local Str:String = "String to convert to a stream~nof thow lines"
Global T:TTextStream = New TTextStream
Local DataStream:TStream =  CreateBankStream(New TBank) 
T = TTextStream.Create(DataStream, TTextStream.UTF16LE) 
T.WriteString(str) 
T.Seek(0) 

While not T.Eof() 
	Print T.ReadLine() 
WEnd


Obviously a TStringStream would be incredible great.


jsp(Posted 2008) [#4]
Sorry to come up with this old thread, but still no TStringStream or have i missed something?


Blueapples(Posted 2008) [#5]
A RAM Stream points directly to a buffer/string. This is faster than the option above since there's no copying involved.

Local str:String
Local stream:TStream

str = "this is a test"
stream = CreateRamStream(str, str.length, True, False)

Print stream.ReadString(5)


But careful with that, writing beyond the length of the stream will cause problems.


jsp(Posted 2008) [#6]

This is faster than the option above since there's no copying involved.



Just what i was looking for, thanks!