Get text until the comma appears Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
euras
Posts: 429
Joined: 05 Nov 2015, 12:56

Get text until the comma appears

23 Mar 2017, 07:38

how to copy text until the comma in the text appears?

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%
garry
Posts: 3770
Joined: 22 Dec 2013, 12:50

Re: Get text until the comma appears  Topic is solved

23 Mar 2017, 07:58

Code: Select all

name := "Surname Another, Name Two"
StringSplit, string, name, `,
msgbox, %string1%
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Get text until the comma appears

23 Mar 2017, 14:58

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
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: ccqcl, Descolada and 183 guests