Edited Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
fivefive
Posts: 60
Joined: 07 May 2022, 14:16

Edited

Post by fivefive » 27 Sep 2022, 23:14

Edited
Last edited by fivefive on 12 Mar 2023, 10:47, edited 1 time in total.

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Extract item name consists of - symbol

Post by BoBo » 27 Sep 2022, 23:23

RegEx should do the trick. Otherwise you can StrSplit() a sentence at the EOL char, then Space chars and check if in any of its items hyphens are InStr().
If true StrReplace() it.

User avatar
flyingDman
Posts: 2817
Joined: 29 Sep 2013, 19:01

Re: Extract item name consists of - symbol  Topic is solved

Post by flyingDman » 28 Sep 2022, 00:33

Code: Select all

var := "These A-P-P-L-E-S are sweet"

regexmatch(var,"(\w-[\w-]*)",m)
msgbox % strreplace(m1,"-")

msgbox % join(strsplit(var,"-")*)
Join(params*)
	{
	last := params.count()
    for x,y in params
        str .= x = last ? substr(y,1,1) : substr(y,-0)
    return str
	}

while pos := InStr(var, "-", , , a_index)
	lst .= (a_index = 1 ? substr(var,pos-1,1) : "") . substr(var,pos+1,1)
msgbox % lst
?
14.3 & 1.3.7

sofista
Posts: 650
Joined: 24 Feb 2020, 13:59
Location: Buenos Aires

Re: Extract item name consists of - symbol

Post by sofista » 28 Sep 2022, 16:20

A RegExReplace approach as an alternative, seems to work but barely tested:

Code: Select all

data := "
(
I love A-P-P-L-E
This A-P-P-L-E is sweet
A-P-P-L-E is awesome
)"

For k, v in StrSplit(data, "`n")
	MsgBox, % RegExReplace(v, "-([A-Z])|([A-Z])(?=-)|.", "$1$2")

Post Reply

Return to “Ask for Help (v1)”