[update: 192 chars]
Code: Select all
/' print-friendly max string (hand-built) - 2024 Aug 17 by dafhi
i've attempted a 128+ print-friendly string so many times, i thought
i would document my process.
update: string length 192
previous version i acknowledge that repeats chars were a thing but forgot to include the first instance
'/
sub if_prepend_exepath( byref filename as string )
for i as long = len(filename) - 1 to 0 step -1
if chr(filename[i]) = "\" or chr(filename[i]) = "/" then exit sub
next
filename = exepath + "\" + filename
end sub
sub string_to_file( byref s as string, filename as string )
var ff = freefile
open filename for output as #ff
write #ff, s
close #ff
end sub
dim as string s = space(255) ' len 255 .. (skipping ascii val zero)
for i as long = 1 to 255
s[i - 1] = i
next
dim as string file_out = "text.txt"
if_prepend_exepath file_out
'' integrity test (one of several)
' string_to_file s, file_out
'' after pasting file content back into IDE (wxFBE), then to HTML code preview and back, i see this
/'
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~¬& !Æ0`9R}"Ü"a:S~x ¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ
'/
'compiler sees at least 3 of those as dbl quotes.
'the real double quote follows exclamation point (last row from above)
' removing line breaks, the real double quote, and 1st fake dbl quote
s = " !#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~¬& !Æ0`9R}"
' remaining data including other fake dbl quote
'Ü"a:S~x ¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ"
' culprit is known among the first few chars from experience. i consecutively 1-char delete-undo till compiler's happy
s += "Üa:S~x ¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ"
'' verify
'string_to_file s, file_out
' from file
s = " !#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~¬& !Æ0`9R}Üa:S~x ¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ"
' experience showed me ascii repeats are a thing, so
dim as string r = space( len(s) )
dim as long bins(), j
redim bins(255)
for i as long = 0 to len(s)-1
dim as long asc_val = s[i]
if bins( asc_val ) = 0 then
r[j] = asc_val
bins( asc_val ) = 1
j += 1
endif
next
'' verify
'? r[j-1] ' non-32
'? r[j] ' 32
r = left( r, j )
'string_to_file r, file_out
'' copied
r = " !#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~¬ÆÜ¡¢£¤¥¦§¨©ª«®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ"
' manually removing [tab] (first char) and per 3.5-Sonnet recommendation & < and >
r = " !#$%'()*+,-./0123456789:;=?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~¬ÆÜ¡¢£¤¥¦§¨©ª«®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ"
' copied back from html
r = " !#$%'()*+,-./0123456789:;=?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~¬ÆÜ¡¢£¤¥¦§¨©ª«®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ"
' out in front that space annoys me
r = "!#$%'() *+,-./0123456789:;=?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~¬ÆÜ¡¢£¤¥¦§¨©ª«®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ"
' after a few attempts i quite like it
' one last verify
function all_unique( byref q as string) as long
dim as ubyte bins(255)
for i as long = 0 to len(q)-1
if bins( q[i] ) then return false
bins( q[i] ) += 1
next
return true
end function
' i think we're good
if all_unique( r ) = false then
print "repeats found"
else
print r
print
print "string length:"; len(r) ' i see length 192 .. not bad!
endif
sleep