Format string with some values like sprintf (C) - Update
- DoubleDutch
- Addict
- Posts: 3219
- Joined: Thu Aug 07, 2003 7:01 pm
- Location: United Kingdom
- Contact:
Wow! I didn't know about that using the single quotes automatically converted to the ASCII of the character.
Is it in the help file?
Is it in the help file?
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
https://reportcomplete.com <- School end of term reports system
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.DoubleDutch wrote:Wow! I didn't know about that using the single quotes automatically converted to the ASCII of the character.
Is it in the help file?
Thank´s ebs.
Opps, i have found big bug by "\n" and "\r", "\n" is newline not carrie line
New:
- Added hexadecimal out "%x" and "%X"
All Updates at first site.
GT
Opps, i have found big bug by "\n" and "\r", "\n" is newline not carrie line
New:
- Added hexadecimal out "%x" and "%X"
All Updates at first site.
GT
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
-
- Addict
- Posts: 4527
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Maybe you are meaning: "\n is line feed not carriage return."?mk-soft wrote:Opps, i have found big bug by "\n" and "\r", "\n" is newline not carrie line
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
Update v1.06
- compatible for X86 and X64
- added type integer (%i)
GT
- compatible for X86 and X64
- added type integer (%i)
GT
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
-
- Always Here
- Posts: 6425
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: Format string with some values like sprintf (C) - Update
Very nice work - would be great to see it formally added to PB.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
Re: Format string with some values like sprintf (C) - Update
Update v2.02
complete new code
Update v2.03
- Bugfix: hex types
complete new code
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
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Re: Format string with some values like sprintf (C) - Update
I'd replace the hex value check with
to make it possible to use other lengths.
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
Re: Format string with some values like sprintf (C) - Update
@pcfreak
updated with your code
Thanks
updated with your code
Thanks
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Re: Format string with some values like sprintf (C) - Update
I use your sprintf in a lot of codes.
For more flexibility please add
so we can mask the percent-char, e.g.
For more flexibility please add
Code: Select all
Case '%' : result + "%"
Code: Select all
this is a testcode works \%100\%
-
- Always Here
- Posts: 6425
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: Format string with some values like sprintf (C) - Update
I think this sprintf function should be added to PB - how about it Fred?
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
Re: Format string with some values like sprintf (C) - Update
It's really nothing... but a handy small partner procedure
Makes handling " characters easier.
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
Re: Format string with some values like sprintf (C) - Update
Handle ["] over [\']
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Re: Format string with some values like sprintf (C) - Update
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
P.S. New Ref v2.07 Ref 2
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)
P.S. New Ref v2.07 Ref 2
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Re: Format string with some values like sprintf (C) - Update
Thanks for sharing. I think there is a bug with hex!
trying your example:
i am getting 00C8FFFF instead of 0000FFFF ?!
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 ?!