Read string file from Datasection

Just starting out? Need help? Post your questions and find answers here.
mag
Enthusiast
Enthusiast
Posts: 104
Joined: Mon Mar 29, 2004 1:46 pm

Read string file from Datasection

Post 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.
infratec
Always Here
Always Here
Posts: 7575
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Read string file from Datasection

Post 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
juergenkulow
Enthusiast
Enthusiast
Posts: 581
Joined: Wed Sep 25, 2019 10:18 am

Re: Read string file from Datasection

Post 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
Please ask your questions, because switch on the cognition apparatus decides on the only known life in the universe.Wersten :DDüsseldorf NRW Germany Europe Earth Solar System Flake Bubble Orionarm
Milky Way Local_Group Virgo Supercluster Laniakea Universe
User avatar
Blue
Addict
Addict
Posts: 964
Joined: Fri Oct 06, 2006 4:41 am
Location: Canada

Re: Read string file from Datasection

Post 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...
PB Forums : Proof positive that 2 heads (or more...) are better than one :idea:
Post Reply