How to creat Tstream from String?
BlitzMax Forums/BlitzMax Programming/How to creat Tstream from String?
| ||
Hi to everyone. I need the best and easy way to creat a TStream from String? Thanks... |
| ||
Depending on what you want to do, RamStreams should do what you want.MyStream = CreateRamStream(MyString, MyString.length, True, False) |
| ||
Ok, thanks i will try that :-D |
| ||
Thats no work for my purpose :( I have this variable: Local myString:String = "something to do" And I make this: Local myStream:TStream = CreateRamStream(myString, myString.length, True, False) Then i do this: Local a:Byte While (a = ReadByte(streamIn)) Print a Wend And nothing are printed, only 0 What can i do? |
| ||
orgos, don't know what your trying to do, but... You can try the following:SuperStrict Local myString:String = "something to test" Local myStream:TStream = CreateRamStream(myString, myString.length, True, False) Local a:Byte Print mystring.length While StreamPos(mystream)<mystring.length Print ReadByte(mystream) Wend CloseStream(mystream) |
| ||
Thanks Shortwind but you have some error on your code The TStream objet not have the length property, instead you must use Size Any way thanks, i solve my problem. |
| ||
The TStream objet not have the length property, instead you must use Size I don't see any reference to a TStream.length ... Whatever, you also can use "Eof" instead of "StreamPos<length" : While Not (Eof(mystream)) Print ReadByte(mystream) Wend ps : you wrote While (a = ReadByte(streamIn)) Print a that is a mistake. You can't allocate "a" while you test it. It's a kind of ambigous statement that should not occure in an 'advanced' language where we would use "==" instead of "=" Here, if you test a=readbyte(...) it will just check the last value of "a" and compare it to Readbyte, but it won't "paste" the ReadByte value to "a" So it's all logical it only prints "0". |
| ||
The TStream objet not have the length property, instead you must use Size If you would've looked at that carefully, you would have noticed that he tagged the ".length" on to a string, which, unless I'm mistaken, is allowed. I don't think you ran his example to begin with, because it works as it should. No bugs whatsoever. EDIT: BTW, this was not directed to Bobysait. :) |
| ||
There is a whole section I personally missed in the docs, under Language -> Strings. You're after: string.ToCString() That will get you a byte array for use with RamStream (or just use the array). |