Jump to content
Sign in to follow this  
User9999

Manipulating Strings

Recommended Posts

User9999

Hello guys,

I have some doubts

I would like to know how to change an STRING in a loop

like :

1st time a1

2nd time a2

3rd time a3

4th time a4

something like that.

And also concatenate the string in a text that I am sending by using Send() method.

Thanks

Share this post


Link to post
Share on other sites
Varian

Not sure if this is what you are looking for

Local $CurrentIteration, $String
For $i = 1 to 10
    $CurrentIteration = 'a' & $i
    $String &= $CurrentIteration & @LF
    MsgBox(262208, 'Current String = ' & $CurrentIteration, 'String = ' & $String)
Next

Share this post


Link to post
Share on other sites
somdcomputerguy

For $i = 1 to 4
    ConsoleWrite("The variable is A" & $i & @LF)
Next

The & character is used to concatenate stuff. See here, http://www.autoitscript.com/autoit3/docs/intro/lang_operators.htm

Edited by somdcomputerguy

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites
Malkey

Allowing for "st, "nd", and "rd".

; Output :-
;1st time a1
;2nd time a2
;3rd time a3
;4th time a4
;....

Local $sStr, $sNumType

For $i = 1 To 24
    Select
        Case Mod($i, 10) = 1
            $sNumType = "st"
        Case Mod($i, 10) = 2
            $sNumType = "nd"
        Case Mod($i, 10) = 3
            $sNumType = "rd"
        Case Else
            $sNumType = "th"
    EndSelect

    If Mod($i, 100) = 11 Or Mod($i, 100) = 12 Or Mod($i, 100) = 13 Then $sNumType = "th"
    $sStr &= $i & $sNumType & " time a" & $i & "{ENTER}" ;  or @LF
Next

Run("notepad.exe")
WinWaitActive("Untitled - Notepad")
WinMove("Untitled - Notepad", "", (@DesktopWidth - 300) / 2, (@DesktopHeight - 650) / 2, 300, 650)
Send($sStr)

Similar to above, but in function form.

; Output :-
;1st time a1
;2nd time a2
;3rd time a3
;4th time a4
;....
; Modified from http://www.autoitscript.com/forum/topic/...-strings/page__view__findpost_
; http://www.autoitscript.com/forum/topic/124334-manipulating-strings/page__view__findpost__p__863571
Local $sStr

For $i = 1 To 24
    $sStr &= $i & _OrdinalAbbrev($i) & " time a" & $i & "{ENTER}" ;  or @LF
Next

Run("notepad.exe")
WinWaitActive("Untitled - Notepad")
WinMove("Untitled - Notepad", "", (@DesktopWidth - 300) / 2, (@DesktopHeight - 650) / 2, 300, 650)
Send($sStr)

; Ordinal abbreviations are actually hybrid contractions of a numeral and a word. 1st is
; "1" + "st" from "first". Similarly, we use "nd" for "second" and "rd" for "third".
; From  http://en.wikipedia.org/wiki/English_numerals
; Returns: Either "st", "nd", "rd", or "th"
;
Func _OrdinalAbbrev($iNum)
    Local $sOrdAbbr
    Select
        Case IsNumber($iNum) = 0 ; If not a number
            Return ""
        Case Mod($iNum, 100) = 11 Or Mod($iNum, 100) = 12 Or Mod($iNum, 100) = 13
            Return "th"
        Case Mod($iNum, 10) = 1
            Return "st"
        Case Mod($iNum, 10) = 2
            Return "nd"
        Case Mod($iNum, 10) = 3
            Return "rd"
        Case Else
            Return "th"
    EndSelect
EndFunc   ;==>_OrdinalAbbrev

Edit: Updated function.

Edited by Malkey

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.