mIRC Homepage

Replace and ....

Posted By: SkyD

Replace and .... - 22/06/06 10:30 AM

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
Posted By: Karas

Re: Replace and .... - 22/06/06 11:09 AM

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
Posted By: schaefer31

Re: Replace and .... - 22/06/06 07:42 PM

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.
© 2021 mIRC Discussion Forums