Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
chris123zugg
Apprentice


Joined: 23 Aug 2013
Posts: 175

PostPosted: Sun Dec 08, 2013 2:32 am   

help with a capture please
 
Hi everyone, and thanks ahead of time for helping!!!


I need to know the correct syntax to turn any numbers that are spelled out, IE: twenty seven, and turn them into a numerical value, BUT I also need to remove a hyphen from the spelled out number's.
IE: twenty-seven


If anyone could help me with this I would greatly appreciate it:)

I have tried %remove, for the hypen, but I've yet to see the correct argument to turn letters to numbers or vice versa.
Reply with quote
chris123zugg
Apprentice


Joined: 23 Aug 2013
Posts: 175

PostPosted: Mon Dec 09, 2013 3:30 am   
 
Actually to further the problem, I need to convert the spelled out number (whatever it may be) and turn it into a numerical value, and i have NO idea how to do that with cmud. So yeah, If someone has smoe spare time and could help thanks!!
Reply with quote
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Mon Dec 09, 2013 6:07 am   
 
Vijilante's Toolbox (available under the library) has a WordstoNumber function. Check it out.
Reply with quote
chris123zugg
Apprentice


Joined: 23 Aug 2013
Posts: 175

PostPosted: Mon Dec 09, 2013 2:29 pm   
 
sweet ty
Reply with quote
chris123zugg
Apprentice


Joined: 23 Aug 2013
Posts: 175

PostPosted: Mon Dec 09, 2013 3:07 pm   
 
Thank you charneus! However that is far beyond me, and i installed it etc., yet it doesn't work. Soooo yeah.
Reply with quote
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Tue Dec 10, 2013 9:26 am   
 
Here, I'm extracting the relevant part, so all you have to do is copy below and paste it in your settings (right-click, paste should work). The syntax is simple: #PRINT @wordstonumber("forty-nine thousand six hundred ninety-four") will return 49694. You can also reverse that with @numbertowords. It worked for me, so not sure why it wouldn't work for you.

Code:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
  <class name="NumberWordConversions" copy="yes">
    <notes>I still have to tweak some stuff in here, I know I can get these faster</notes>
    <func name="NumberToWords" type="Literal" copy="yes">
      <value>#IF ($Number="") {#RETURN ""}
$new=""
#WHILE ($new!=$Number) {
 $new=$Number
 $Number=%subregex($new,"((? }
#IF (%begins($Number,",")) {$Number=%right($Number,1)}
$Number=%replace($Number,",","|")
$new=""
$Words="One|Two|Three|Four|Five|Six|Seven|Eight|Nine|Ten|Eleven|Twelve|Thirteen||Fifteen"
$WordCompound="|Twenty|Thirty|Forty|Fifty"
$Groups="|Thousand|Million|Billion|Trillion|Quadrillion|Quintillion"
#WHILE ($Number) {
 $Pos=%item($Number,1)
 $added=0
 #IF (%len($Pos)=3) {
  $val=%left($Pos,1)
  #IF ($val) {
   $new=%concat($new," ",%item($Words,$val)," Hundred")
   $added=1
  }
  $Pos=%right($Pos,1)
 }
 $val=%left($Pos,1)
 #IF (($val="0")||($val="1")) {
  $val=%number($Pos)
  #IF ($val>0) {
   #IF (%item($Words,$val)) {
    $new=%concat($new," ",%item($Words,$val))
   } {
    $val=%item($Words,($val\10))
    #IF (%ends($val,"t")) {$val=%concat($val,"een")} {$val=%concat($val,"teen")}
    $new=%concat($new," ",$val)
   }
   $added=1
  }
 } {
  $val=(%number($Pos)/10)
  $Pos=%item($Words,(%number($Pos)\10))
  #IF (%item($WordCompound,$val)) {
   $new=%concat($new," ",%item($WordCompound,$val))
   #IF ($Pos) {
    $new=%concat($new,%if($NoUseDash," ","-"),$Pos)
   }
  } {
   #IF ($val) {
    $val=%item($Words,$val)
    #IF (%ends($val,"t")) {$val=%concat($val,"y")} {$val=%concat($val,"ty")}
    $new=%concat($new," ",$val)
   }
   #IF ($Pos) {
    $new=%concat($new,%if($val,%if($NoUseDash," ","-")),$Pos)
   }
  }
  $added=1
 }
 #IF ($added) {
  $val=%item($Groups,%numitems($Number))
  #IF ($val) {$new=%concat($new," ",$val,%if($AddCommas,","))}
 }
 #DELNITEM $Number 1
}
#IF (%ends($new,",")) {$new=%leftback($new,1)}
#RESULT %trim($new)</value>
      <arglist>$Number,$NoUseDash,$AddCommas</arglist>
    </func>
    <func name="WordsToNumber" type="Literal" copy="yes">
      <value>#IF ($Words="") {#RETURN 0}
$NWords="One|Two|Three|Four|Five|Six|Seven|Eight|Nine|Ten|Eleven|Twelve|Thirteen|Fourteen|Fifteen|Sixteen|Seventeen|Eighteen|Nineteen"
$WordCompound="|Twenty|Thirty|Forty|Fifty"
$Groups="|Thousand|Million|Billion|Trillion|Quadrillion|Quintillion"
$Words=%replace($Words,",","")
$ResText=""
$ResNumber=0
$GroupText=""
#WHILE ($Words) {
 #IF (%regex($Words,%concat("(.*?(?:\z",$Groups,"))"),$GroupText)!=0) {
  $Words=%trim(%remove($GroupText,$Words))
  $GroupText=%replace($GroupText,"-"," ")
  $LastWord=%word($GroupText,%numwords($GroupText))
  $Places=%ismember($LastWord,$Groups)
  #IF ($Places) {$GroupText=%trim(%remove($LastWord,$GroupText))}
  $word=%word($GroupText,1)
  $num=%ismember($word,$NWords)
  #IF ($num) {
   $GroupText=%trim(%remove($word,$GroupText))
   #IF (%lower(%word($GroupText,1))="hundred") {
    $GroupText=%trim(%remove(%word($GroupText,1),$GroupText))
    $ResNumber=($ResNumber+$num*100*%concat("1",%repeat("000",($Places-1))))
    $word=%word($GroupText,1)
   } {
    $ResNumber=($ResNumber+$num*%concat("1",%repeat("000",($Places-1))))
    $word=%word($GroupText,1)
   }
  }
  #IF (%ends($word,"ty")) {
   $num=%ismember($word,$WordCompound)
   #IF ($num) {
    $GroupText=%trim(%remove($word,$GroupText))
    $word=%word($GroupText,1)
    $ResNumber=($ResNumber+$num*10*%concat("1",%repeat("000",($Places-1))))
   } {
    $num=%ismember(%leftback($word,2),$NWords)
    #IF ($num) {
     $GroupText=%trim(%remove($word,$GroupText))
     $word=%word($GroupText,1)
     $ResNumber=($ResNumber+$num*10*%concat("1",%repeat("000",($Places-1))))
    } {
     $num=%ismember(%leftback($word,1),$NWords)
     #IF ($num) {
      $GroupText=%trim(%remove($word,$GroupText))
      $word=%word($GroupText,1)
      $ResNumber=($ResNumber+$num*10*%concat("1",%repeat("000",($Places-1))))
     } {
      $ResText=%concat($GroupText,$Words)
      $Words=""
      //error state
     }
    }
   }
  }
  #IF ($word) {
   $num=%ismember($word,$NWords)
   #IF ($num) {
    #ADD $ResNumber ($num*%concat("1",%repeat("000",($Places-1))))
    $GroupText=%trim(%remove($word,$GroupText))
    $word=%word($GroupText,1)
    #IF ($word) {
     $ResText=%concat($GroupText,$Words)
     $Words=""
     //error state
    }
   } {
    $ResText=%concat($GroupText,$Words)
    $Words=""
    //error state
   }
  }
 } {
  $ResText=$Words
  $Words=""
 }
}
#RETURN %trim(%concat(%format(%if($AddCommas,"&amp;.0n","&amp;s"),$ResNumber)," ",$ResText))</value>
      <arglist>$Words,$AddCommas</arglist>
    </func>
  </class>
</cmud>
Reply with quote
chris123zugg
Apprentice


Joined: 23 Aug 2013
Posts: 175

PostPosted: Tue Dec 10, 2013 8:56 pm   
 
aye, i misstated...It doesn't work the way i need it to.;] Thanks again though!
Reply with quote
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Tue Dec 10, 2013 9:27 pm   
 
Well, tell us what it's not doing that you want it to... we can't help otherwise...
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net