Posted: 19th Mar 2004 11:19
simple aint it

+ Code Snippet
print justifyRight("something", 20)
print justifyRight("thing", 20)
print justifyRight("A doggy!", 20)


suspend for key


function justifyRight(string$ as string, length as integer)
   L = len(string$)
   LL = length - len(string$)

   for t=1 to LL
      string$ = " " + string$
   next t
endfunction string$
Posted: 19th Mar 2004 19:18
Nifty, I can see some uses for that. I was playing with Mojo World Transporter and during initialization it used a right justified HUD like scrolling window for the system messages.
--
TAZ
Posted: 24th Mar 2004 14:57
Even simpler ...

+ Code Snippet
function justifyRight(string$ as string, length as integer)
   if len(string$) < length then string$=space$(length-len(string$))+string$
endfunction string$
Posted: 24th Mar 2004 16:54
oooo, a space$() command. I didn't know that was there. But what if you wanted to fill the space in with a different character?
Posted: 26th Mar 2004 23:44
Dunno - let me play a while
Posted: 27th Mar 2004 0:18
Well, first I tried this

+ Code Snippet
function BuildString1(Ch as string, Size as integer)
   local Count as integer

   Ch = left$(Ch, 1)
   if Ch = " " then exitfunction space$(Size)

   Count=1
   while (Count+Count) < Size
      Ch = Ch + Ch
      Count = Count+Count
   endwhile

   Ch = left$(Ch, Size - Count) + Ch
endfunction Ch


Result? Abysmal speed

Next, I tried to see what effect the windows message checking had on the speed by changing the while loop into a for loop.

+ Code Snippet
function BuildString2(Ch as string, Size as integer)
   local Count as integer

   Ch = left$(Ch, 1)
   if Ch = " " then exitfunction space$(Size)

   for Count=1 to Size step Count
      Ch = Ch + Ch
   next Count

   Ch = left$(Ch, Size - (Count/2) ) + Ch
endfunction Ch


Then I decided to skip all that crap ...

+ Code Snippet
function BuildString3(Ch as string, Size as integer)
   local c as integer

   C = asc( Ch )

   Ch = space$(Size)
   fill memory get string ptr(Ch), C, Size
endfunction Ch


Build a string the fast way (using space$) and then blat the right characters over the top.

The timing results on my PC for building 1000 strings of 100000 characters in length ...

1 - 6310 ms
2 - 5167 ms
3 - 931 ms

[EDIT]The last one needs my Utility plug-in[/EDIT]
Posted: 28th Mar 2004 0:08
i was gonna say, whats that fill memory? I thin i got your plugin.
Posted: 28th Mar 2004 13:56
FILL MEMORY is a standard DBPro command. You just need my plug-in to get the address of the string in memory (get string ptr).