I try this one, but it gives me a text AFTER the comma, not BEFORE it.
Code: Select all
name := "Surname Another, Name Two"
StringSplit, string, name, `,
string := string%string0%
msgbox, %string%
Code: Select all
name := "Surname Another, Name Two"
StringSplit, string, name, `,
string := string%string0%
msgbox, %string%
Code: Select all
name := "Surname Another, Name Two"
StringSplit, string, name, `,
msgbox, %string1%
Code: Select all
q:: ;get string before first comma
;get string before first comma, or nothing if there are no commas
vText := "text with no commas"
MsgBox % (vPos := InStr(vText, ",")) ? SubStr(vText, 1, vPos-1) : ""
vText := "text, with, commas"
MsgBox % (vPos := InStr(vText, ",")) ? SubStr(vText, 1, vPos-1) : ""
;more simply:
;if (vPos := InStr(vText, ","))
; vOutput := SubStr(vText, 1, vPos-1)
;else
; vOutput := ""
;MsgBox % vOutput
;get string before first comma, or whole string if there are no commas
;to get the whole string for times when there are no commas,
;add a comma to the end of the haystack (e.g. vText ",")
vText := "text with no commas"
MsgBox % SubStr(vText, 1, InStr(vText ",", ",")-1)
vText := "text, with, commas"
MsgBox % SubStr(vText, 1, InStr(vText ",", ",")-1)
Return