Page 1 of 1

WritePreferenceString with leading spaces

Posted: Mon Sep 15, 2008 10:55 am
by Michael Vogel
Hi,
just wondered that WritePreferenceString does not use doublequotes at the beginning and end of the string?!

ReadPreferenceString() works fine with values like...

Code: Select all

value = " test "
...but when rewriting this back to a preference file, it is seen as...

Code: Select all

value =  test 
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

Posted: Mon Sep 15, 2008 12:53 pm
by Kukulkan
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

Posted: Mon Sep 15, 2008 2:13 pm
by AND51
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)

Posted: Mon Sep 15, 2008 3:13 pm
by Kukulkan
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

Posted: Mon Sep 15, 2008 3:59 pm
by AND51
Ouuups! :oops:

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. :lol:

Posted: Mon Sep 15, 2008 4:04 pm
by ts-soft
> Eigentlich
is german, i think "in fact" is the right vocable

Posted: Mon Sep 15, 2008 4:24 pm
by AND51
@ TS-Soft
:wink: In fact, I know...
:wink: :wink: And in fact, you can also use "actually" for "eigentlich"; it's the same.
:wink: :wink: :wink: It's only a little joke.

Posted: Mon Sep 15, 2008 4:47 pm
by Kukulkan
Hi,

In my opinion, Eigentlich is best translated with in fact.

Kukulkan