mIRC Homepage
Posted By: Blurshape on INPUT question - 16/05/03 06:50 PM
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!
Posted By: Jesper Re: on INPUT question - 16/05/03 07:23 PM
Like:

All My Words Should Start With $Upper
or
Only my first word should be $upper ?
Posted By: Anonymous Re: on INPUT question - 16/05/03 07:26 PM
I made this a long time ago
Code:
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 Test

Edit1: InstCaps = Instant Caps just in case you wondered

Edit2: hmm .. upon re-reading your post, you could just use
Code:
alias instcap return $+($upper($left($1-,1)),$lower($right($1-,-1)))


//echo -a $instcap(this is a test) will return This is a test
Posted By: codemastr Re: on INPUT question - 16/05/03 07:39 PM
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,
Code:
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.
Posted By: Anonymous Re: on INPUT question - 16/05/03 07:42 PM
that too smile
I should have hit refresh before I edited my post
Posted By: Blurshape Re: on INPUT question - 16/05/03 08:22 PM
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...
Posted By: Blurshape Re: on INPUT question - 16/05/03 08:28 PM
doesn't seem to work.. i just use it by "/caps something here." right? or is there another way?
Posted By: codemastr Re: on INPUT question - 16/05/03 08:28 PM
No problem, if it doesn't work right let me know, I didn't do too much testing on it.
Posted By: Blurshape Re: on INPUT question - 16/05/03 08:34 PM
wait, I got it grin thanks for the help!
Posted By: Pap Re: on INPUT question - 17/05/03 10:51 AM
try this:
Code:
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. grin

My friend says he has an alias that does this:
Code:
/heh /say heh
Posted By: ChamuR Re: on INPUT question - 17/05/03 01:03 PM
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 }
Posted By: codemastr Re: on INPUT question - 17/05/03 05:19 PM
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.
Posted By: Nimue Re: on INPUT question - 17/05/03 07:02 PM
//echo -a $caps(there is a problem, it loses commas!)
Posted By: codemastr Re: on INPUT question - 17/05/03 07:09 PM
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!
Posted By: Nimue Re: on INPUT question - 17/05/03 07:26 PM
I didn't change much. smile
Code:
alias caps {
  var %ii = 1, %r
  while $ [ $+ [ %ii ] ] {
    var %a = $ifmatch
    var %i = $calc($len(%a) -1)
    var %out
    while (%i &gt; 0) {
      if ($mid(%a,%i,1) == $chr(32) &amp;&amp; $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)
}
Posted By: Nimue Re: on INPUT question - 17/05/03 10:56 PM
Code:
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 &gt; 0) {
    if ($mid($1-,%i,1) == $chr(32) &amp;&amp; $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. laugh
Posted By: codemastr Re: on INPUT question - 17/05/03 11:59 PM
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...
Posted By: qwerty Re: on INPUT question - 18/05/03 11:53 AM
$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:
Code:
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) smile
Posted By: bcummings Re: on INPUT question - 03/08/04 10:45 PM
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

Posted By: bcummings Re: on INPUT question - 04/08/04 01:48 AM
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}
© mIRC Discussion Forums