mIRC Home    About    Download    Register    News    Help

Print Thread
Preserve Spacing #114014 11/03/05 03:55 AM
Joined: Mar 2005
Posts: 7
T
tabby Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
T
Joined: Mar 2005
Posts: 7
A really annoying thing i dont like is that mIRC doesn't preserve spacing in output etc. Yes, this is easily delt with, $str($chr(160),10) etc.. The annoying part is when $read'ing a file (*.txt) and it not preserving it when you output it.

The only way you can do it is open the .txt file do a mass replace on " " and replace it with $chr(160) ... This doesn't work too well when u want people to upload files and people can view them.... you need to manually replace all the spaces to chr160..

I tried making a loop to get every character from a file and try and makr a 'replace' in mirc to do it, but it doesn't 'see' the normal chr32 spaces so you cant replace them ...

Anyone successfully done this, if not, then khaled should probably support it

Thanks

Re: Preserve Spacing #114015 11/03/05 04:38 AM
Joined: Sep 2003
Posts: 4,230
D
DaveC Offline
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Code:
alias Asc0x20toAsc0xA0 {
  .fclose Asc0x20toAsc0xA0*
  .fopen Asc0x20toAsc0xA0 $$1-
  if (!$fopen(Asc0x20toAsc0xA0).err) {
    var %i = 0
    var %s = 1048576
    .fseek Asc0x20toAsc0xA0 %i
    while ($fread(Asc0x20toAsc0xA0,%s,&binvar)) {
      breplace &binvar 32 160
      .fseek Asc0x20toAsc0xA0 %i
      .fwrite -b Asc0x20toAsc0xA0 &binvar
      inc %i %s
      .fseek Asc0x20toAsc0xA0 %i
    }
    bunset &binvar
  }
  .fclose Asc0x20toAsc0xA0*
}


I dont think the inital fseek is needed, and maybe also the one on the end of the loop, but it makes it a little clear whats happening.
Maybe i shouldnt have used &binvar as the var name either but i did smile

* note binary file access starts at byte zero

Re: Preserve Spacing #114016 11/03/05 12:34 PM
Joined: Jan 2003
Posts: 2,523
Q
qwerty Offline
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Identifiers can handle multiple spaces fine. $read() is a bit different, because it also evaluates the line read, so multiple spaces are truncated. To prevent that, use the n switch, then a $replace() to replace all spaces (char 32) with char 160:
Code:
$replace($read(file.txt,[color:red]n[/color]),$chr(32),$chr(160))

By the way, using char 160 to display spaces isn't recommended for a script that's going to be public. The reason is that char 160 isn't a space on certain (console) fonts. Personally, instead of replacing spaces with char 160, I insert ^B (ctrl+B, bold) pairs between two consecutive spaces. The ^B^B pair itself isn't visible but forces mirc to display two spaces in a row. Here's an alias that automatically inserts all the necessary ^B pairs in the input string:
Code:
alias keepspaces var %a | !.echo -q $regsub($1,/(?<=^| )(?=$| )/g,$str($chr(2),2),%a) | return %a

Example usage: //echo -a $keepspaces($read(file.txt,n))


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com