Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Convert strings with columns
#1
How can I convert

this

in

this?

Sorry, I don't know how paste in text mode with columns...


Attached Files Image(s)
       
#2
Macro Macro630
Code:
Copy      Help
out
str s=
;AAAAAAAAAAAA     BBBBBBBBBBBBBBB     CCCCCCCCCC
;;;;11111             22222               333
;;;;11111             22222               333

str s2
ARRAY(str) ar ac ac0
ar=s

tok ar[0] ac0 -1 " "
str f.format("%%%is %%%is %%%is[]" (ac0[0].len) (ac0[1].len) (ac0[2].len))

int i
for i 0 ar.len
,tok ar[i] ac -1 " "
,s2.formata(f ac[0] ac[1] ac[2])

out s2
#3
Thanks.

Is possible regardless of the number of columns (like a function)?
#4
Member function str.CompactTextTable
Code:
Copy      Help
;/
function [flags] ;;flags: 1 right-align

;Removes unnecessary spaces from text table columns.

;EXAMPLE
;str s=
;;AAAAAAAAA     BBBBBBBBBB     CCCCCCCCC
;;;;;1111          2222           33
;;;;;11111         22222          333
;
;s.CompactTextTable(1)
;out s


ARRAY(str) ar ac af ;;rows, columns, format
ARRAY(int) aw ;;column widths

ar=this

int i j k nc

;column widths
for i 0 ar.len
,k=tok(ar[i] ac -1 " ")
,if(i=0) nc=k; aw.create(nc); else if(k!=nc) end ES_BADARG
,for j 0 nc
,,k=ac[j].len
,,if(k>aw[j]) aw[j]=k

;format
af.create(nc)
str f=iif(flags&1 "%%%is " "%%-%is ")
for(i 0 nc) af[i].format(f aw[i])
af[i-1].set("[]" (af[i-1].len-1))

;create table
this=""
for i 0 ar.len
,tok(ar[i] ac -1 " ")
,for(j 0 nc) this.formata(af[j] ac[j])
#5
Incredible.

You make it look easy.

Thanks again.

be missing only center... Wink
#6
Do you know how to align in text types like ARIAL, TIMES NEW ROMAN...?
#7
Too difficult. Need to get device context of the window where the text will be displayed, and calculate text width with GetTextExtentPoint32 and similar functions. Alignment will not be perfect.
#8
and using minimum quantity of [9]?
#9
Replace tabs to spaces.
#10
I don't understand.

What I mean is that it may be easier to do it with tabs.


Attached Files Image(s)
   
#11
Not easier to write such function. Anyway, tabs will not help with variable width font.


Forum Jump:


Users browsing this thread: 1 Guest(s)