Jump to content

Convert first letter to small letter


Recommended Posts

  • Moderators

Another way:

StringLower(StringLeft($sString, 1)) & StringTrimLeft($sString, 1)

And another:

StringRegExpReplace($sString, "(.)(.*?)$", StringLower(StringLeft($sString, 1)) & "$2")

And another:

StringLower(StringSplit($sString, "", 2)[0]) & StringTrimLeft($sString, 1)

I could probably do this all day.

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

Link to comment
Share on other sites

@SmOke_N - I hope that is not in response to me...

edit: Was thinking more of a way to use a bitwise operator to add 32 ( or whatever the offset is) to the 1ST byte. 

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

  • Moderators

@kylomas

Global $gsOut = ((StringIsLower(StringLeft($sString, 1))) ? $sString : Chr(BitXOR(Asc(StringLeft($sString, 1)), 32)) & StringTrimLeft($sString, 1))

Edit:

Or:

Global $gsOut = ((StringIsLower(StringLeft($sString, 1))) ? $sString : Chr(BitXOR(StringToASCIIArray($sString)[0], 32)) & StringTrimLeft($sString, 1))
Edited by SmOke_N

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

This is using the regular expression unicode character property for lower case, "p{Ll}",  to check if the first character is lower case.  Ref. from here.

Local $sString = "Local $sString"
Global $gsOut = StringRegExp($sString, "^\p{Ll}") ? $sString : (Chr(Asc(StringLeft($sString, 1)) + 32) & StringMid($sString, 2))
ConsoleWrite($gsOut & @LF)
Edited by Malkey
Link to comment
Share on other sites

Here is an example with CharLowerBuff

$string = "UPPER_TO_LOWER"
$length = 1

Func _CharLowerBuff($string, $length)
    $ret = DllCall("user32.dll", "DWORD", "CharLowerBuff", "str", $string, "DWORD", $length)
    Return $ret[1]
EndFunc    ;==> _CharLowerBuff

MsgBox(0, "_CharLowerBuff()", _CharLowerBuff($string, $length))    ; ==> uPPER_TO_LOWER
or

$string = "UPPER_TO_LOWER"
$length = 1

$ret = DllCall("user32.dll", "DWORD", "CharLowerBuff", "str", $string, "DWORD", $length)

MsgBox(0, "CharLowerBuff()", $ret[1])    ; ==> uPPER_TO_LOWER
Edited by kaesereibe
Link to comment
Share on other sites

  • Moderators

Or

MsgBox(0, "CharLowerBuff()", DllCall("user32.dll", "DWORD", "CharLowerBuff", "str", "UPPER_TO_LOWER", "DWORD", 1)[1])    ; ==> uPPER_TO_LOWER

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

A DLL call seems a LITTLE bit over the top just to make a letter lower cased.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

  • Moderators

@BrewManNH... everyone is just playing around after the first few working examples in the post.  But I'd prefer to use the DLL call myself to be honest (if it were wrapped).

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

Yeah, but it's one command built into the language, and we let AutoIt worry about the implementation of it. I personally don't care HOW it's done I just want to get it done.

I want a quarter inch hole, not a quarter inch drill.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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...