Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Michael Vogel
Addict
Posts: 2797 Joined: Thu Feb 09, 2006 11:27 pm
Contact:
Post
by Michael Vogel » Mon Sep 15, 2008 10:55 am
Hi,
just wondered that WritePreferenceString does not use doublequotes at the beginning and end of the string?!
ReadPreferenceString() works fine with values like...
...but when rewriting this back to a preference file, it is seen as...
So the next time it will be only "test" without the spaces...
Is this like it should work? Do I have to add the doublequotes by myself or could this be a problem (with future versions)?
Code: Select all
If Trim(Text)<>Text
Text=#DOUBLEQUOTE$+Text+#DOUBLEQUOTE$
EndIf
WritePreferenceString(Name,Text)
Michael
Kukulkan
Addict
Posts: 1396 Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:
Post
by Kukulkan » Mon Sep 15, 2008 12:53 pm
Hi Michael,
I suggest you to store such values in base64 encoded format (now usable in unicode executables, too
)
Code: Select all
; encodes a string to Base64 encoding
Procedure.s b64encode(Original.s)
If Original.s = "": ProcedureReturn "": EndIf
Result.s = Space(StringByteLength(Original.s) * 1.36)
length.l = Base64Encoder(@Original.s, StringByteLength(Original.s), @Result.s, Len(Result.s))
ProcedureReturn Left(Result.s, length.l)
EndProcedure
; decodes a Base64 encoded string
Procedure.s b64decode(Encoded.s)
If Encoded.s = "": ProcedureReturn "": EndIf
Result.s = Space(StringByteLength(Encoded.s))
length.l = Base64Decoder(@Encoded.s, StringByteLength(Encoded.s), @Result.s, Len(Result.s))
ProcedureReturn Left(Result.s, length.l)
EndProcedure
Debug Chr(34)+b64decode(b64encode("This is a test string"))+Chr(34)
Kukulkan
Last edited by
Kukulkan on Mon Sep 15, 2008 3:13 pm, edited 2 times in total.
AND51
Addict
Posts: 1040 Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:
Post
by AND51 » Mon Sep 15, 2008 2:13 pm
Kukulan, funzt nicht richtig!
You must correct your procedure, I've just tested it for validity.
Code: Select all
; encodes a string to Base64 encoding
Procedure.s b64encode(Original.s)
If Original.s = "": ProcedureReturn "": EndIf
Result.s = Space(Len(Original.s) * 1.36)
length.l = Base64Encoder(@Original.s, Len(Original.s), @Result.s, Len(Result.s))
ProcedureReturn Left(Result.s, length.l)
EndProcedure
; decodes a Base64 encoded string
Procedure.s b64decode(Encoded.s)
If Encoded.s = "": ProcedureReturn "": EndIf
Result.s = Space(Len(Encoded.s))
length.l = Base64Decoder(@Encoded.s, Len(Encoded.s), @Result.s, Len(Result.s))
ProcedureReturn Left(Result.s, length.l)
EndProcedure
Debug Chr(34)+b64decode(b64encode("Aha-Erlebnis!"))+Chr(34)
Kukulkan
Addict
Posts: 1396 Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:
Post
by Kukulkan » Mon Sep 15, 2008 3:13 pm
Hi And51,
Thank you. You are right if you say that the code did not work in unicode-executables. I corrected this in the code postet above. Now the code works in both variations (ascii and unicode).
Kukulkan
AND51
Addict
Posts: 1040 Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:
Post
by AND51 » Mon Sep 15, 2008 3:59 pm
Ouuups!
I didn't say the word "unicode", actually... Somehow I forgot it. I have uicode activated by default so I didn't thought this is the actueal reason.
Eigentlich, it was your own idea.
ts-soft
Always Here
Posts: 5756 Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany
Post
by ts-soft » Mon Sep 15, 2008 4:04 pm
> Eigentlich
is german, i think "in fact" is the right vocable
PureBasic 5.73 |
SpiderBasic 2.30 |
Windows 10 Pro (x64) |
Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
AND51
Addict
Posts: 1040 Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:
Post
by AND51 » Mon Sep 15, 2008 4:24 pm
@ TS-Soft
In fact, I know...
And in fact, you can also use "actually" for "eigentlich"; it's the same.
It's only a little joke.
Kukulkan
Addict
Posts: 1396 Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:
Post
by Kukulkan » Mon Sep 15, 2008 4:47 pm
Hi,
In my opinion, Eigentlich is best translated with in fact .
Kukulkan