Using StringReplace
Using StringReplace
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
Re: Using StringReplace
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.
Re: Using StringReplace
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
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