String to Buffer

BlitzMax Forums/BlitzMax Programming/String to Buffer

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

if the null character is an issue i think you may be ok. the following does not print "null".

Framework BRL.Basic

Local teststr:String="different"
DebugLog(teststr)

Local test:TBank=New TBank

' create a stream to access the bank
Local tstream:TBankStream=TBankStream.create(test)
Local testptr:Byte Ptr=teststr.ToCString()

For i=0 To teststr.length-1
	If (testptr[i]=0)
		DebugLog("null")
	EndIf
	DebugLog(Chr(testptr[i]))
	' write the char to the bank
	tstream.writeBytes(Chr(testptr[i]),1)
Next

teststr=String.FromCString(test.Buf())

DebugLog(teststr)



or, you can write directly from the string without converting to a pointer first:

Framework BRL.Basic

Local teststr:String="different"
DebugLog(teststr)

Local test:TBank=New TBank

' create a stream to access the bank
Local tstream:TBankStream=TBankStream.create(test)

For i=0 To teststr.length-1
	DebugLog(Chr(teststr[i]))
	' write the char to the bank
	tstream.writeBytes(Chr(teststr[i]),1)
Next

teststr=String.FromCString(test.Buf())

DebugLog(teststr)