How to separate a string with vary length of spaces in between. Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
songdg
Posts: 604
Joined: 04 Oct 2017, 20:04

How to separate a string with vary length of spaces in between.

25 Mar 2024, 22:21

How to separate a string with vary length of spaces in between, I want all the text be separate into an array of words with length of 2, StrSplit(text1 , "A_Space"), StrSplit(text2 , "A_Space"), StrSplit(text3 , "A_Space") would get the same result as "aaaaa" and "bbbbb", how to do that.

Code: Select all

text1 := "aaaaa bbbbb"
text2 := "aaaaa      bbbbb"
text3 := "aaaaa   bbbbb"
User avatar
Seven0528
Posts: 390
Joined: 23 Jan 2023, 04:52
Location: South Korea
Contact:

Re: How to separate a string with vary length of spaces in between.  Topic is solved

25 Mar 2024, 23:21

Code: Select all

#Requires AutoHotkey v2.0
#SingleInstance Force
str := "aaaaa   bbbbb"
list := strSplit(regExReplace(str," +"," ")," ")
msgbox list[1] ;  "aaaaa"
msgbox list[2] ;  "bbbbb"
  • English is not my native language. Please forgive any awkward expressions.
  • 영어는 제 모국어가 아닙니다. 어색한 표현이 있어도 양해해 주세요.
User avatar
flyingDman
Posts: 2828
Joined: 29 Sep 2013, 19:01

Re: How to separate a string with vary length of spaces in between.

25 Mar 2024, 23:55

Code: Select all

text := "aaaaa      bbbbb"
msgbox strsplit(text," "," ",2)[1]
msgbox strsplit(text," "," ",2)[2]
14.3 & 1.3.7
songdg
Posts: 604
Joined: 04 Oct 2017, 20:04

Re: How to separate a string with vary length of spaces in between.

26 Mar 2024, 22:32

Seven0528 wrote:
25 Mar 2024, 23:21

Code: Select all

#Requires AutoHotkey v2.0
#SingleInstance Force
str := "aaaaa   bbbbb"
list := strSplit(regExReplace(str," +"," ")," ")
msgbox list[1] ;  "aaaaa"
msgbox list[2] ;  "bbbbb"
Thanks, much appreciated :bravo:
songdg
Posts: 604
Joined: 04 Oct 2017, 20:04

Re: How to separate a string with vary length of spaces in between.

26 Mar 2024, 22:33

flyingDman wrote:
25 Mar 2024, 23:55

Code: Select all

text := "aaaaa      bbbbb"
msgbox strsplit(text," "," ",2)[1]
msgbox strsplit(text," "," ",2)[2]
Thanks, really appreciated :thumbup:

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: Albireo, Sem552, shipaddicted and 22 guests