Using StringReplace

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
codude
Posts: 128
Joined: 12 Nov 2015, 05:33

Using StringReplace

17 Sep 2017, 21:17

I have a string that I paste into a field that is limited to 60 characters. I need to have a dash between each word in this string. After the string is pasted I use this StringReplace script StringReplace, Clipboard, Clipboard, %A_SPACE%, -, The problem is if I paste a string that does not completely fill the field I get dashes for each space after the last word up till the 60th character. I found that after pasting if I back the cursor up to the end of the last word it solves this problem. If I just take my mouse and put the cursor after the last word that does not work and I still get all these dashes. If I could find a way that the script is only looking for a single space to replace, this would solve my problems unless there happened to be just one space left after the last word and I would again get a dash. I could probably live with this if there are no other solutions. Thanks
codude
Posts: 128
Joined: 12 Nov 2015, 05:33

Re: Using StringReplace

17 Sep 2017, 22:26

If there is a way to determine if the cursor is currently on a text/character or maybe a blank space I could continue to back up the cursor until this was (or was not) the case.
codude
Posts: 128
Joined: 12 Nov 2015, 05:33

Re: Using StringReplace

20 Sep 2017, 16:28

This seemed to work.
Send ^a
Sleep 20
Send ^c
Sleep 20
send ^v
Sleep 20

Loop
{
StringRight, OutputVar, Clipboard, 1
If (OutputVar <> " ")
{
break
}
else
{
Send {BackSpace}
Sleep 20
Send ^a
Sleep 20
Send ^c
Sleep 20
send ^v
Sleep 20
}
}

;Replace spaces with dashes

StringReplace, Clipboard, Clipboard, %A_SPACE%, -, UseErrorLevel
If ErrorLevel
{
TrayTip,%ErrorLevel%,%Clipboard%,,1
}
Else
TrayTip,,%ErrorLevel%,,1
Sleep 20
Send ^a
Sleep 20

send ^v

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: filipemb, mikeyww, PsysimSV and 278 guests