Edited Topic is solved
Re: Extract item name consists of - symbol
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.
If true StrReplace() it.
- flyingDman
- Posts: 2817
- Joined: 29 Sep 2013, 19:01
Re: Extract item name consists of - symbol Topic is solved
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
Re: Extract item name consists of - symbol
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")