Page 1 of 1

Read string file from Datasection

Posted: Thu Jan 12, 2023 8:58 pm
by mag
I would like to attach a string file name 'test.txt' which have a normal ascii text. This file I want to attach to exe at Datasection.

Image

The code is look like this:

Code: Select all

TextString$ = ""

Restore TextLabel:
Read.s TextString$
MessageRequester("Example","The first embedded text is: " + Chr(10) + TextString$,0)

DataSection
	
  	TextLabel:
  	IncludeBinary "test.txt"
  	Data.s ""  ; Make sure we have a nul to stop the string read
EndDataSection
The problem is; the outcome from Read.s is not in Ascii. Look at this outcome.

Image

How can I set to Read.s in ASCII format like in ReadFile() command which has flags option.
#PB_Ascii : all read string operation will use ASCII if not specified otherwise.
#PB_UTF8 : all read string operation will use UTF-8 if not specified otherwise (default).
#PB_Unicode: all read string operation will use Unicode if not specified otherwise.

Re: Read string file from Datasection

Posted: Thu Jan 12, 2023 9:03 pm
by infratec

Code: Select all

MessageRequester("Example", "The first embedded text is: " + #LF$ + PeekS(?TextLabel, -1, #PB_Ascii)

DataSection
  	TextLabel:
  	IncludeBinary "test.txt"
  	Data.s ""  ; Make sure we have a nul to stop the string read
EndDataSection

Re: Read string file from Datasection

Posted: Fri Jan 13, 2023 3:08 am
by juergenkulow
You generate:

Code: Select all

unsigned char pb_data[] = {239,187,191,83,116,114,105,110,103,32,70,114,111,109,32,70,105,108,101
,0,0
};

Code: Select all

file=CreateFile(#PB_Any,"/tmp/test.txt",#PB_Unicode)
WriteString(file,"String From File",#PB_Unicode)
generate:

Code: Select all

unsigned char pb_data[] = {83,0,116,0,114,0,105,0,110,0,103,0,32,0,70,0,114,0,111,0,109,0,32,0,70,0,105,0,108,0,101,0
,0,0

Re: Read string file from Datasection

Posted: Mon May 01, 2023 4:54 am
by Blue
infratec wrote: Thu Jan 12, 2023 9:03 pm

Code: Select all

MessageRequester("Example", "The first embedded text is: " + #LF$ + PeekS(?TextLabel, -1, #PB_Ascii)
[...]
Thanks infratec.
I had forgotten (something I do a lot these days) how easy it is...