Sign in to follow this  
Followers 0
DarkBoost

count letters in a word

11 posts in this topic

I am sorry for such a simple query but I am struggling to find the answer :D

"LetterCount()" obviously does not exist:

;Example

$word = "hello"

MsgBox(0,"",$word & " has (" & LetterCount($word) & ") letters")

Share this post


Link to post
Share on other sites



@herewasplato... champion!!!

Share this post


Link to post
Share on other sites

thanks for the quick responses.

i have a text document with 500+ employee's names and trying to create a script which will scramble the words... like a game... and output to another text document for staff to play.

original text document (correct names):

bruce wayne

peter parker

bruce banner

...

new text document (scrambled):

eurbc neywa =

eetpr rkrape =

bceur nneabr =

...

I am unsure which approach to take to achieve this and if their may already be a simple String command which may easily achieve this.

Share this post


Link to post
Share on other sites

first you want to separate the first and last name so they don't get mixed. So you want to use string split

Next you want to split up the letters using a for loop and stringtrimleft or right.

Then use random to scramble them up.

The For loop to get the letters will probably take some work, just look up the functions in the help file


Giggity

Share this post


Link to post
Share on other sites

Why do random when you can have fun? ^_^

#include <INet.au3>
#include <String.au3>
#include <Array.au3>

_Main()

Exit

Func _Main()
    Local $aNames[3][2] = [["bruce wayne", ""], ["peter parker", ""], ["bruce banner", ""]], $i
    For $i = 0 To 2
        $aNames[$i][1] = _GetAnagram($aNames[$i][0])
    Next
    _ArrayDisplay($aNames)
EndFunc

Func _GetAnagram($sString)
    $sString = StringReplace($sString, " ", "+")
    Local $sURL = "http://www.anagramgenius.com/server.php?source_text=" & $sString & "&emphasis=1&gender=2&vulgar=0&seen=true"
    Local $sSource = _INetGetSource($sURL)
    If @error Then Return SetError(1, 0, "")
    Local $aResults = StringRegExp($sSource, "(?U)<span class=""black-18"">.*</span>", 3)
    If @error Then Return SetError(2, 0, "")
    Local $aAnagrams = _StringBetween($aResults[1], "<span class=""black-18"">'", ".'</span>")
    If @error Then Return SetError(3, 0, "")
    Return SetError(0, 0, StringLower($aAnagrams[0]))
EndFunc

WBD

Share this post


Link to post
Share on other sites

I was bored, so...

#include <Array.au3>

Dim $aResult[1]

$sInfile = @ScriptDir & "\names.txt"
$sOutfile = @ScriptDir & "\scramble.txt"

$hInfile = FileOpen($sInfile, 0)
$hOutfile = FileOpen($sOutfile, 2)

If $hInfile <> -1 And $hOutfile <> -1 Then
    While 1
        $sFullname = FileReadLine($hInfile)
        If @error Then ExitLoop
        $aFullname = StringSplit($sFullname, " ")
        If IsArray($aFullname) Then
            ReDim $aResult[$aFullname[0]]
            For $i=1 To $aFullname[0]
                $aResult[$i - 1] = _ScrambleWord($aFullname[$i])
            Next
            FileWriteLine($hOutfile, _ArrayToString($aResult, " "))
        EndIf
    WEnd
    FileClose($hInfile)
    FileClose($hOutfile)
EndIf

    
Func _ScrambleWord($sWord)
    Local $aScramble[1]
    Local $aWord = StringSplit($sWord, "", 2)
    If IsArray($aWord) Then
        While UBound($aWord) > 1
            $iIdx = Random(0, UBound($aWord) - 1, 1)
            _ArrayAdd($aScramble, $aWord[$iIdx])
            _ArrayDelete($aWord, $iIdx)
        WEnd
        _ArrayAdd($aScramble, $aWord[0])
        _ArrayDelete($aScramble, 0)
        Return _ArrayToString($aScramble, "")
    EndIf
    Return ""
EndFunc

Share this post


Link to post
Share on other sites

@WBD

LOL!!!!

what happens if an anagram cannot be found? you should use a backup standard (boring...) scrambler.

PS. added all that password stuff to the UDF of yours, a bit off topic but ah well

Share this post


Link to post
Share on other sites

... trying to create a script which will scramble the words... like a game...

Just be sure that you do not generate some "not safe for work" words :-)

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0