Jump to content

Get the first letter?


 Share

Recommended Posts

Hi,

I need to get the first letter of for exemple "$letter"

I want to split it in 10 parts to make it like this:

Letter A-D: Call "Function blabla"

Letter E-G: Call "Function blabla"

Letter H-K: Call "Function blabla"

....

Thank you :P

Cool board, always fast help :lmao:

Link to comment
Share on other sites

  • Moderators

Man...

That makes no sense... 10 parts x's 4 letters = 40 Letters?

What have you tried?

What does an example look like in your script that you would get?

What would the end result be?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

$letter = "gah"

$s_letter = StringMid(StringUpper($letter),1,1)
Select
    Case $s_letter = 'A' Or $s_letter = 'B'  Or $s_letter = 'C'  Or $s_letter = 'D'
        MsgBox(0,"1st case",$s_letter)
    Case $s_letter = 'E'  Or $s_letter = 'F'  Or $s_letter = 'G'
        MsgBox(0,"2nd case",$s_letter)
    Case $s_letter =  'H' Or $s_letter = 'I'  Or $s_letter = 'J'  Or $s_letter = 'K'
        MsgBox(0,"3rd case",$s_letter)
EndSelect

Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

$letter = "gah"

$a_letter = StringMid(StringUpper($letter),1,1)
    Select
        Case $a_letters[$x] = 'A' Or $a_letters[$x] = 'B'  Or $a_letters[$x] = 'C'  Or $a_letters[$x] = 'D'
            MsgBox(0,"1st case",$a_letters[$x])
        Case $a_letters[$x] = 'E'  Or $a_letters[$x] = 'F'  Or $a_letters[$x] = 'G'
            MsgBox(0,"2nd case",$a_letters[$x])
        Case $a_letters[$x] =  'H' Or $a_letters[$x] = 'I'  Or $a_letters[$x] = 'J'  Or $a_letters[$x] = 'K'
            MsgBox(0,"3rd case",$a_letters[$x])
    EndSelect
Hmm could you explain what this is doing please? =)

thank you for your help

Link to comment
Share on other sites

Hmm could you explain what this is doing please? =)

thank you for your help

I changed it, realized you only wanted to know 1st letter, it was going thru each letter.

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

  • Moderators

Hey that's nice Gary!!... I did something like that once... but a bit drawn out :P

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Func ChooseEncryption()
    $a_letter = StringMid(StringUpper($Username),1,1)
    Select
        Case $a_letters[$x] = 'A' Or $a_letters[$x] = 'B'  Or $a_letters[$x] = 'C'  Or $a_letters[$x] = 'D'
            MsgBox(0,"1st case",$a_letters[$x])
        Case $a_letters[$x] = 'E'  Or $a_letters[$x] = 'F'  Or $a_letters[$x] = 'G'
            MsgBox(0,"2nd case",$a_letters[$x])
        Case $a_letters[$x] =  'H' Or $a_letters[$x] = 'I'  Or $a_letters[$x] = 'J'  Or $a_letters[$x] = 'K'
            MsgBox(0,"3rd case",$a_letters[$x])
        Case $a_letters[$x] =  'H' Or $a_letters[$x] = 'L'  Or $a_letters[$x] = 'M'  Or $a_letters[$x] = 'N'
            MsgBox(0,"4rd case",$a_letters[$x])
        Case $a_letters[$x] =  'M' Or $a_letters[$x] = 'O'  Or $a_letters[$x] = 'P'  Or $a_letters[$x] = 'Q'
            MsgBox(0,"5rd case",$a_letters[$x])
        Case $a_letters[$x] =  'R' Or $a_letters[$x] = 'S'  Or $a_letters[$x] = 'T'  Or $a_letters[$x] = 'U'
            MsgBox(0,"6rd case",$a_letters[$x])
        Case $a_letters[$x] =  'V' Or $a_letters[$x] = 'W'  Or $a_letters[$x] = 'X'  Or $a_letters[$x] = 'Y' Or $a_letters[$x] = 'Z'
            MsgBox(0,"7rd case",$a_letters[$x])
                Else
                Msgbox(0,"Error","Invalid Username!")
    EndSelect
Endfunc

Case $a_letters[$x] = 'A' Or $a_letters[$x] = 'B' Or $a_letters[$x] = 'C' Or $a_letters[$x] = 'D'

Case ^Error

Error: Variable used without being declared

hmmm... I cant declare every Variable in my script....

This would be 30 more lines? :P

Edited by sd333221
Link to comment
Share on other sites

Func ChooseEncryption()
    $a_letter = StringMid(StringUpper($Username),1,1)
    Select
        Case $a_letters[$x] = 'A' Or $a_letters[$x] = 'B'  Or $a_letters[$x] = 'C'  Or $a_letters[$x] = 'D'
            MsgBox(0,"1st case",$a_letters[$x])
        Case $a_letters[$x] = 'E'  Or $a_letters[$x] = 'F'  Or $a_letters[$x] = 'G'
            MsgBox(0,"2nd case",$a_letters[$x])
        Case $a_letters[$x] =  'H' Or $a_letters[$x] = 'I'  Or $a_letters[$x] = 'J'  Or $a_letters[$x] = 'K'
            MsgBox(0,"3rd case",$a_letters[$x])
        Case $a_letters[$x] =  'H' Or $a_letters[$x] = 'L'  Or $a_letters[$x] = 'M'  Or $a_letters[$x] = 'N'
            MsgBox(0,"4rd case",$a_letters[$x])
        Case $a_letters[$x] =  'M' Or $a_letters[$x] = 'O'  Or $a_letters[$x] = 'P'  Or $a_letters[$x] = 'Q'
            MsgBox(0,"5rd case",$a_letters[$x])
        Case $a_letters[$x] =  'R' Or $a_letters[$x] = 'S'  Or $a_letters[$x] = 'T'  Or $a_letters[$x] = 'U'
            MsgBox(0,"6rd case",$a_letters[$x])
        Case $a_letters[$x] =  'V' Or $a_letters[$x] = 'W'  Or $a_letters[$x] = 'X'  Or $a_letters[$x] = 'Y' Or $a_letters[$x] = 'Z'
            MsgBox(0,"7rd case",$a_letters[$x])
                Else
                Msgbox(0,"Error","Invalid Username!")
    EndSelect
Endfunc

Case $a_letters[$x] = 'A' Or $a_letters[$x] = 'B' Or $a_letters[$x] = 'C' Or $a_letters[$x] = 'D'

Case ^Error

Error: Variable used without being declared

hmmm... I cant declare every Variable in my script....

This would be 30 more lines? :P

just to tell you why it hasn't worked:

you declared "$a_letter" as your array, but you checked "$a_letters", this way it can't work

Link to comment
Share on other sites

Hello

StringRegExp could be a good solution for this kind of test.

$letter = "ah !!!!!!"
$a_letter = FirstLetter( StringMid(StringUpper($letter),1,1) )

$letter = "Flunch !!!!!!"
$a_letter = FirstLetter( StringMid(StringUpper($letter),1,1) )

$letter = "Hiiiii !!!!!!"
$a_letter = FirstLetter( StringMid(StringUpper($letter),1,1) )

Func FirstLetter( $a_letter )
    Select
        Case StringRegExp($a_letter,"^[ABCDE]",0)
            MsgBox(0,"1st case",$a_letter)
        Case StringRegExp($a_letter,"^[EFG]",0)
            MsgBox(0,"2nd case",$a_letter)
        Case StringRegExp($a_letter,"^[HIJK]",0)
            MsgBox(0,"3rd case",$a_letter)
        EndSelect
endfunc

HTH,

Francis

Link to comment
Share on other sites

or if you have beta switch

$letter = "gah"
Switch StringMid(StringUpper($letter), 1, 1)
   Case 'A' To 'D'
      MsgBox(0, "1st case", $a_letter)
   Case 'E' To 'G'
      MsgBox(0, "2nd case", $a_letter)
   Case 'H' To 'K'
      MsgBox(0, "3rd case", $a_letter)
EndSwitch
Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

$firstletter = Asc(StringLeft($username,1)) it will return the ASCII code for the caractere after you do case like other post

case $firstletter > 64 and $firstletter < 69 or $firstletter > 96 and $firstletter < 101

blabla

65 to 68 = A,B,C,D

97 to 100 = a,b,c,d

is another way to do it!

with less coding

if username is not case sentive you can format $username to get the proper case and analyse it after! it will be a little faster!

and many thx for the Switch function gafrost! it pretty kewl!

Edited by Greenseed

GreenseedMCSE+I, CCNA, A+Canada, QuebecMake Love Around You.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...