mIRC Homepage
Posted By: tabby Preserve Spacing - 11/03/05 03:55 AM
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
Posted By: DaveC Re: Preserve Spacing - 11/03/05 04:38 AM
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
Posted By: qwerty Re: Preserve Spacing - 11/03/05 12:34 PM
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))
© mIRC Discussion Forums