mIRC Home    About    Download    Register    News    Help

Print Thread
#151811 22/06/06 10:30 AM
Joined: Feb 2005
Posts: 74
S
SkyD Offline OP
Babel fish
OP Offline
Babel fish
S
Joined: Feb 2005
Posts: 74
Hi!
I have a little problem.
How can i replace text width *?
Like that: My_text shoud be ******* . I need it for trivia.

And how i can partition a text like that:
Whats my dog name?*alfred

I need to partition that. And then have to bee question and answer.
Whats my dog name?
alfred

Sorrryy for english! frown


[color:red]m[color:blue]IRC[color:green] for EvEr

#151812 22/06/06 11:09 AM
Joined: Jul 2005
Posts: 40
K
Ameglian cow
Offline
Ameglian cow
K
Joined: Jul 2005
Posts: 40
Quote:
Hi!
I have a little problem.
How can i replace text width *?
Like that: My_text shoud be ******* . I need it for trivia.


/help $replace
/help $str
/help $len
* = $chr(42) [ascii]

//echo -a Blahblhablha $hide(LOL) blahblha
Code:
alias hide {
return $replace($1,$1,$str($chr(42),$len($1)))
}


Quote:

And how i can partition a text like that:
Whats my dog name?*alfred

I need to partition that. And then have to bee question and answer.
Whats my dog name?
alfred

Sorrryy for english! frown


Using tokens, /help Token Identifiers
Code:
var %text = Whats my dog name?*alfred
 $gettok(%text,1,42) -->  Whats my dog name?
 $gettok(%text,2,42) --> alfred


j0k3r @ k4s.ch
#151813 22/06/06 07:42 PM
Joined: Aug 2005
Posts: 525
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Aug 2005
Posts: 525
Quote:
//echo -a Blahblhablha $hide(LOL) blahblha
Code:
alias hide {
return $replace($1,$1,$str($chr(42),$len($1)))
}


And what if the text contains spaces, punctuation or other non-word characters?

//echo -a $hide(It's some text!) --> ***************

Technically, that result is correct, but for the sake of a trivia bot should be **'* **** ****!


You could correct that by modifying the code similar to the following:

Code:
alias hide {
  var %t = $replace($1,$chr(32),$chr(160)), %i = 1, %l = $len(%t), %h
  while (%i <= %l) {
    if ($mid(%t,%i,1) isalnum) %h = $+(%h,*)
    else %h = $+(%h,$mid(%t,%i,1))
    inc %i
  }
  return $replace(%h,$chr(160),$chr(32))
}


//echo -a $hide(It's some text!) --> **'* **** ****!

However, that's slow and ugly. It can be reduced to a simple regsubex that accomplishes the same task much faster, especially when dealing with long strings of text.

Code:
alias hide return $regsubex($1,/([^\W_]+)/g,$str(*,$len(\t)))


//echo -a $hide(#1 trivia superstar!) --> #* ****** *********!

Note: mIRC 6.17 is required to use $regsubex.


Link Copied to Clipboard