Page 2 of 5

Posted: Sat Jul 19, 2008 12:50 am
by DoubleDutch
Wow! I didn't know about that using the single quotes automatically converted to the ASCII of the character. :D

Is it in the help file?

Posted: Sat Jul 19, 2008 4:23 am
by Demivec
DoubleDutch wrote:Wow! I didn't know about that using the single quotes automatically converted to the ASCII of the character. :D

Is it in the help file?
The only place I could find it mentioned was under the topic of the "Asc()" function. It is a function that operates at compile-time and is used with constants.

Posted: Sat Jul 19, 2008 12:32 pm
by mk-soft
Thank´s ebs.

Opps, i have found big bug by "\n" and "\r", "\n" is newline not carrie line :oops:

New:
- Added hexadecimal out "%x" and "%X"

All Updates at first site.

GT :wink:

Posted: Sat Jul 19, 2008 1:16 pm
by Little John
mk-soft wrote:Opps, i have found big bug by "\n" and "\r", "\n" is newline not carrie line :oops:
Maybe you are meaning: "\n is line feed not carriage return."?
That's right, but "\n" does not always mean new line. ;)
For denoting a new line, Mac uses "\r", *nix uses "\n", and windows uses "\r\n".

Regards, Little John

Posted: Fri Mar 27, 2009 2:33 pm
by mk-soft
Update v1.06
- compatible for X86 and X64
- added type integer (%i)

GT :wink:

Re: Format string with some values like sprintf (C) - Update

Posted: Sun Jan 03, 2010 9:01 am
by IdeasVacuum
Very nice work - would be great to see it formally added to PB.

Re: Format string with some values like sprintf (C) - Update

Posted: Wed Jan 20, 2010 7:16 pm
by mk-soft
Update v2.02
complete new code 8)

Update v2.03
- Bugfix: hex types

Code: Select all

valuelong.l = $12341FE0
valueword.w = $EEEE
valueinteger.i = $12345

Debug Format("%X", @valueinteger) ; Fehler
Debug Format("%12.8X", @valuelong) ; Breite 12, Type Long
Debug Format("%'#12.8X", @valuelong) ; Auffüllung mit '#' ; Breite 12, Type Long
Debug Format("%4X", @valueword) ; Ohne Breite ist Type ; Type Word
Debug Format("%8X", @valuelong)  ; Ohne Breite ist Type ; Type Long
Debug Format("%'#12.4X", @valueword)  ; Auffüllung mit '#' ; Breite 12, Type Word

Re: Format string with some values like sprintf (C) - Update

Posted: Fri Jan 27, 2012 7:32 pm
by pcfreak
I'd replace the hex value check with

Code: Select all

                Select num2
                  Case 0 To 2  : help = RSet ( Hex ( PeekB ( *value ), #PB_Byte), num2, "0" )
                  Case 3 To 4  : help = RSet ( Hex ( PeekW ( *value ), #PB_Word), num2, "0" )
                  Case 5 To 8  : help = RSet ( Hex ( PeekL ( *value ), #PB_Long), num2, "0" )
                  Default      : help = RSet ( Hex ( PeekQ ( *value ), #PB_Quad), num2, "0" )
                EndSelect
to make it possible to use other lengths.

Re: Format string with some values like sprintf (C) - Update

Posted: Wed Feb 08, 2012 8:19 am
by mk-soft
@pcfreak

updated with your code

Thanks

Re: Format string with some values like sprintf (C) - Update

Posted: Tue Aug 28, 2012 4:47 pm
by VoSs2o0o
I use your sprintf in a lot of codes.

For more flexibility please add

Code: Select all

Case '%' : result + "%"
so we can mask the percent-char, e.g.

Code: Select all

this is a testcode works \%100\% 

Re: Format string with some values like sprintf (C) - Update

Posted: Tue Aug 28, 2012 5:26 pm
by IdeasVacuum
I think this sprintf function should be added to PB - how about it Fred?

Re: Format string with some values like sprintf (C) - Update

Posted: Thu Jan 22, 2015 7:27 pm
by Rinzwind
It's really nothing... but a handy small partner procedure

Code: Select all

Procedure.s FormatQ ( text.s, *value1 = 0, *value2 = 0, *value3 = 0, *value4 = 0, *value5 = 0, *value6 = 0, *value7 = 0, *value8 = 0, *value9 = 0, *value10 = 0, *value11 = 0 )
  ReplaceString(text, "'", #DOUBLEQUOTE$, #PB_String_InPlace)
  ProcedureReturn Format(text, *value1, *value2, *value3, *value4, *value5, *value6, *value7, *value8, *value9, *value10, *value11)
EndProcedure
Makes handling " characters easier.

Re: Format string with some values like sprintf (C) - Update

Posted: Fri May 01, 2015 11:49 am
by mk-soft
Handle ["] over [\']

Re: Format string with some values like sprintf (C) - Update

Posted: Fri May 01, 2015 11:52 am
by mk-soft
Hello,

after a long time a new update

Update v2.07
- added: unsigned byte
- added: unsigned word
- added: character '\%'
- change: remove most peek functions

Example

Code: Select all

IncludeFile "Format-v207.pbi"

bVal.b = 100
wVal.w = 200
lVal.l = 300
iVal.i = 400
fVal.f = 500.0
dVal.d = 600.0
sVal.s = "Hello World"
aVal.a = 255
uVal.u = 65535

temp.s = "Result: \nByte = %b, \nWord = %w, \nLong = %l, \nInteger = %i, \nFloat = %10.2f, \nDouble = %+10.2d, \n"
temp + "String = %s, \nUnsigned Byte = %a, \nUnsigned Word = %u,\n"
temp + "Hex = %2x, \nHex = %4X\n"

result.s = format(temp, @bVal, @wVal, @lVal, @iVal, @fVal, @dVal, @sVal, @aVal, @uVal, @aVal, @uVal)
MessageRequester("Format like sprintf", result)
:wink:

P.S. New Ref v2.07 Ref 2

Re: Format string with some values like sprintf (C) - Update

Posted: Fri May 01, 2015 11:45 pm
by said
Thanks for sharing. I think there is a bug with hex!

trying your example:

Code: Select all

temp.s = "Result: \nByte = %b, \nWord = %w, \nLong = %l, \nInteger = %i, \nFloat = %10.2f, \nDouble = %+10.2d, \n"
temp + "String = %s, \nUnsigned Byte = %a, \nUnsigned Word = %u,\n"
temp + "Hex = %2x, \nHex = %8X\n"   ; <--- chaning to 8X

i am getting 00C8FFFF instead of 0000FFFF ?!