|
Joined: Apr 2006
Posts: 2
Bowl of petunias
|
OP
Bowl of petunias
Joined: Apr 2006
Posts: 2 |
How to replace alternative letters in a word or sentence, ignoring capital letters and spaces?
examples: A Few Good Men --> A F*w G*o* M*n Scent of a Woman -> S*e*t O* A W*m*n Scream --> S*r*a*
Thanks
|
|
|
|
Joined: Aug 2005
Posts: 525
Fjord artisan
|
Fjord artisan
Joined: Aug 2005
Posts: 525 |
$replace(text/phrase, text/letter to replace, text/letter to replace with)
Examples:
$replace(It is a good day, good, bad) ---> It is a bad day $replace(AaAa, a , b) ---> bbbb
There is also $replacecs() which takes the same parameters, and can be used to specifically replace capitals with capitals, lower with lower, etc.
Examples:
$replacecs(AaAa, a, x, A, Y) ---> YxYx $replacecs(It is a Good day and a good month, good, bad) ---> It is a Good day and a bad month
Also look at /help $replace
|
|
|
|
Joined: Apr 2006
Posts: 2
Bowl of petunias
|
OP
Bowl of petunias
Joined: Apr 2006
Posts: 2 |
I was thinking more about that old "Hint challenge" stuff...
|
|
|
|
Joined: Aug 2005
Posts: 525
Fjord artisan
|
Fjord artisan
Joined: Aug 2005
Posts: 525 |
Try this: Useage: $chint(text) alias chint {
if (!$isid) return
var %text = $replace($strip($1-),$chr(32),$chr(183))
var %i = 1, %l = $numtok(%text,183)
var %tok, %toklen, %j, %result
while (%i <= %l) {
var %tmp
%tok = $gettok(%text,%i,183)
%toklen = $len(%tok)
%j = 1
while (%j <= %toklen) {
if ($calc(%j % 2)) %tmp = $+(%tmp,$mid(%tok,%j,1))
else %tmp = $+(%tmp,_)
inc %j
}
%result = $+(%result,$chr(183),%tmp)
inc %i
}
return $replace(%result,$chr(183),$chr(32))
}
|
|
|
|
Joined: Sep 2003
Posts: 4,230
Hoopy frood
|
Hoopy frood
Joined: Sep 2003
Posts: 4,230 |
Scent of a Woman -> S*e*t O* A W*m*n I beleive your example is incorrect by the way. to what you requested at least. Scent of a Woman -> S*e*t *f * W*m*n Scent Of A Woman -> S*e*t O* A Wo*a* Anyway, assuming its what ya requested, try this usage is $makestars(<your text here>) * Your text should be any one line of text, not exceeding 400 characters. alias makestars {
var %text = $replacecs($1-,*,$cr,$chr(32),$lf,a,*a,b,*b,c,*c,d,*d,e,*e,f,*f,g,*g,h,*h,i,*i,j,*j,k,*k,l,*l,m,*m,n,*n,o,*o,p,*p,q,*q,r,*r,s,*s,t,*t,u,*u,v,*v,w,*w,x,*x,y,*y,z,*z)
var %i = 1
while ($pos(%text,*,%i)) {
var %text = $+($left(%text,$calc($v1)),$mid(%text,$calc($v1 + 2)))
inc %i
if ($pos(%text,*,%i)) {
var %text = $+($left(%text,$calc($v1 - 1)),$mid(%text,$calc($v1 + 1)))
}
}
return $replace(%text,$cr,*,$lf,$chr(32))
}
|
|
|
|
Joined: Aug 2005
Posts: 525
Fjord artisan
|
Fjord artisan
Joined: Aug 2005
Posts: 525 |
I interpreted his request as follows, which is how I made the code:
The replacement should start at the second letter of each word and then every other letter after that, still within the current word.
|
|
|
|
Joined: Sep 2003
Posts: 4,230
Hoopy frood
|
Hoopy frood
Joined: Sep 2003
Posts: 4,230 |
Oh i never said your code was wrong (actually i never even checked it, i assumed it worked due to the level of complexity it looked like it had [ie: i assumed you didnt write it in the editor here]) I just mentioned his "How to replace alternative letters in a word or sentence, ignoring capital letters and spaces?" didnt gel with his examples.
To me he said take every other lowercase letter and make it a *. He never said to capitalize anything so i assumed he botched his example (i make no refrence to your code, i dont know f it caps or not)
|
|
|
|
|