|
Joined: Dec 2002
Posts: 8
Nutrimatic drinks dispenser
|
OP
Nutrimatic drinks dispenser
Joined: Dec 2002
Posts: 8 |
How might I go about making a remote for an "on INPUT" that uses $replace to make the first letter (and only the first letter) of every sentence capitalized? example:
First word in this sentence is capitalized. Now the first word in this sentence is capitalized.
Any ideas?
Thanks in advance!
-Erik.
|
|
|
|
Joined: Jan 2003
Posts: 96
Babel fish
|
Babel fish
Joined: Jan 2003
Posts: 96 |
Like:
All My Words Should Start With $Upper or Only my first word should be $upper ?
|
|
|
|
Anonymous
Unregistered
|
Anonymous
Unregistered
|
I made this a long time ago
alias instcaps {
tokenize 32 $lower($1-) | var %i = 1
while ($eval($+($chr(36),%i),2) != $null) {
var %tok = $eval($+($chr(36),%i),2)
var %r = %r $+($upper($left(%tok,1)),$right(%tok,-1))
inc %i
}
return %r
}
//echo -a $instcaps(this is a test) will return This Is A TestEdit1: InstCaps = Instant Caps just in case you wonderedEdit2: hmm .. upon re-reading your post, you could just use
alias instcap return $+($upper($left($1-,1)),$lower($right($1-,-1)))
//echo -a $instcap(this is a test) will return This is a test
Last edited by r0ck; 16/05/03 07:37 PM.
|
|
|
|
Joined: Dec 2002
Posts: 2,809
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 2,809 |
Well thats not what he asked for though. First letter of first word of each sentence, not first letter of every word. It may seem like an easy task, but it can actually get rather complex, for example, what is a "sentence"? What characters can it end with? ?!. most likely. But if you just go through and capitalize the first letter after a period, http://www.test.com becomes http://www.Test.Com, so that's not going to work correctly,
alias caps {
var %i = $calc($len($1-) -1)
var %out
while (%i > 0) {
if ($mid($1-,%i,1) == $chr(32) && $mid($1-,$calc(%i -1),1) isin .?!) {
set %out $upper($mid($1-,$calc(%i +1),1)) $+ %out
}
else {
set %out $mid($1-,$calc(%i +1),1) $+ %out
}
dec %i
}
set %out $upper($mid($1-,%i,1)) $+ %out
return %out
}
$caps(this is a sentence. this is another sentence! this is a third sentence?) = This is a sentence. This is another sentence! This is a third sentence? So that appears to work. But just a note, to prevent the stated problem on urls, it recognizes the end of a sentence as ". " "? " and "! " meaning if there is not a space after the punctuation, then it won't capitalize, it's not a bug, it is how I designed it.
|
|
|
|
Anonymous
Unregistered
|
Anonymous
Unregistered
|
that too I should have hit refresh before I edited my post
|
|
|
|
Joined: Dec 2002
Posts: 8
Nutrimatic drinks dispenser
|
OP
Nutrimatic drinks dispenser
Joined: Dec 2002
Posts: 8 |
ah yeah, I should've been more specific about the puncuation. you've got it the way I was looking for though, whereas a sentence is anything ending with "!", ".", or "?"
so, thanks for the code, i'll test it now...
-Erik.
|
|
|
|
Joined: Dec 2002
Posts: 8
Nutrimatic drinks dispenser
|
OP
Nutrimatic drinks dispenser
Joined: Dec 2002
Posts: 8 |
doesn't seem to work.. i just use it by "/caps something here." right? or is there another way?
-Erik.
|
|
|
|
Joined: Dec 2002
Posts: 2,809
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 2,809 |
No problem, if it doesn't work right let me know, I didn't do too much testing on it.
|
|
|
|
Joined: Dec 2002
Posts: 8
Nutrimatic drinks dispenser
|
OP
Nutrimatic drinks dispenser
Joined: Dec 2002
Posts: 8 |
wait, I got it thanks for the help!
-Erik.
|
|
|
|
Joined: Mar 2003
Posts: 32
Ameglian cow
|
Ameglian cow
Joined: Mar 2003
Posts: 32 |
try this:
on *:INPUT:*:{
if ( $left($1,1) == / || $ctrlenter == $true ) { return }
haltdef
say $upper($left($1,1)) $+ $right($1-,-1)
}
You can hit Ctrl+Enter instead of Enter to escape it. Next thing you know you'll want to add " $+ . " to the end of it, right? hehe Edit: I forgot you wanted the first letter of each sentence... that only does the very first letter. Well that's a start for the rest of you guys. Good luck. I suggest you just unlazy yourself and learn to type proper. My friend says he has an alias that does this:
Last edited by Pap; 17/05/03 11:09 AM.
|
|
|
|
Joined: May 2003
Posts: 3
Self-satisified door
|
Self-satisified door
Joined: May 2003
Posts: 3 |
on *:INPUT:*:if ($left($1,1) != $readini($mircdirmirc.ini,text,commandchar)) && ($active != Status Window) || ($ctrlenter = $true) { var %x = 1,%y | while (%x <= $numtok($1-,32)) { %y = %y $+($upper($left($gettok($1-,%x,32),1)),$lower($mid($gettok($1-,%x,32),2))) | inc %x } | msg $active %y | unset %x %y | halt }
It's not that I'm afraid to die, I just don't want to be there when it happens.
|
|
|
|
Joined: Dec 2002
Posts: 2,809
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 2,809 |
Seriously, does anyone read the original post? This is the third snippet that does NOT do what he asked. There have been ones that capitalize the first letter of every word (like this one), which is not what he asked. There was one that capitalized the first letter of just the first word, which is also not what he asked, he asked for it to capitalize the first letter of EVERY sentence, not every word, and not just the first word. The first word of EVERY sentence.
|
|
|
|
Joined: Dec 2002
Posts: 699
Fjord artisan
|
Fjord artisan
Joined: Dec 2002
Posts: 699 |
//echo -a $caps(there is a problem, it loses commas!)
|
|
|
|
Joined: Dec 2002
Posts: 2,809
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 2,809 |
Yea well... yell at mIRC for that, as far as I know there is no real work around for that, which falls back to my suggestion of mIRC should be like other languages and support quotes!
|
|
|
|
Joined: Dec 2002
Posts: 699
Fjord artisan
|
Fjord artisan
Joined: Dec 2002
Posts: 699 |
I didn't change much. alias caps {
var %ii = 1, %r
while $ [ $+ [ %ii ] ] {
var %a = $ifmatch
var %i = $calc($len(%a) -1)
var %out
while (%i > 0) {
if ($mid(%a,%i,1) == $chr(32) && $mid(%a,$calc(%i -1),1) isin .?!) {
set %out $upper($mid(%a,$calc(%i +1),1)) $+ %out
}
else {
set %out $mid(%a,$calc(%i +1),1) $+ %out
}
dec %i
}
%r = %r %out $+ ,
inc %ii
}
return $left(%r,-1)
}
|
|
|
|
Joined: Dec 2002
Posts: 699
Fjord artisan
|
Fjord artisan
Joined: Dec 2002
Posts: 699 |
alias caps {
var %i = 1, %a, %out
while $ [ $+ [ %i ] ] { %a = %a $ifmatch $+ , | inc %i }
tokenize 32 $left(%a,-1)
%i = $calc($len($1-) -1)
while (%i > 0) {
if ($mid($1-,%i,1) == $chr(32) && $mid($1-,$calc(%i -1),1) isin .?!) {
%out = $upper($mid($1-,$calc(%i +1),1)) $+ %out
}
else { %out = $mid($1-,$calc(%i +1),1) $+ %out }
dec %i
}
set %out $upper($mid($1-,%i,1)) $+ %out
return %out
} I should have tested it.
|
|
|
|
Joined: Dec 2002
Posts: 2,809
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 2,809 |
That gave me an idea, maybe if you use $1-, if $isid it should return it EXACTLY as entered, meaning $blah(test, test,test) $1 = test $2 = test $3 = test $1- = test, test,test
I can't really think of a situation where you would ever request all the params passed to an identifier other than if you wanted to use it as text...
|
|
|
|
Joined: Jan 2003
Posts: 2,523
Hoopy frood
|
Hoopy frood
Joined: Jan 2003
Posts: 2,523 |
$caps(How many, 0, 1 or 2?) This example input breaks the ident, because the 1st while loop doesn't discriminate between $null, $false or 0. I'd use something like this: while $ [ $+ [ %i ] ] != $null { %a = %a $ifmatch $+ , | inc %i } Well, in fact I wouldn't even bother making something like this, the scripter should just do a /var %a = <whatever input> and use $caps(%a)
/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
|
|
|
|
Joined: Aug 2004
Posts: 3
Self-satisified door
|
Self-satisified door
Joined: Aug 2004
Posts: 3 |
hello, a newbie here I used this: alias instcaps { tokenize 32 $lower($1-) | var %i = 1 while ($eval($+($chr(36),%i),2) != $null) { var %tok = $eval($+($chr(36),%i),2) var %r = %r $+($upper($left(%tok,1)),$right(%tok,-1)) inc %i } return %r} and it works great if i copy and paste from someones list into the channel... but if I use the person's Trigger, it all comes in lower case... every word. Is there another snippet to use? I want to make the 1st letter of each word capitalized. Thank you
|
|
|
|
Joined: Aug 2004
Posts: 3
Self-satisified door
|
Self-satisified door
Joined: Aug 2004
Posts: 3 |
Actually, the snippet does not work to capitalize the first letter of each word. The file I was getting was already capitalized correctly. But when I deliberately got a file from someone that had no capitalization....... that's how it came to me.... All Lower-case. So, I sure do need a snippet to put into my Scripts Editor that will Capitalize the first Letter of each Word in the file name.
this is the snippet I used: alias caps { var %i = 1, %a, %out while $ [ $+ [ %i ] ] { %a = %a $ifmatch $+ , | inc %i } tokenize
32 $left(%a,-1) %i = $calc($len($1-) -1) while (%i > 0) { if ($mid($1-,%i,1) == $chr(32) &&
$mid($1-,$calc(%i -1),1) isin .?!) { %out = $upper($mid($1-,$calc(%i +1),1)) $+ %out } else {
%out = $mid($1-,$calc(%i +1),1) $+ %out } dec %i } set %out $upper($mid($1-,%i,1)) $+ %out return
%out}
|
|
|
|
|