AutoHotkey Community

It is currently May 27th, 2012, 2:43 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: November 23rd, 2009, 10:35 pm 
I'm trying to find each word in the sentence and store it in word%a_index%.

Code:
pos = 1
sentence = Test this sentence, okay?
done := strLen(sentence)
while (pos < done)
{
  pos := RegExMatch(sentence, "([a-zA-Z]+)", temp, %pos%)
  word%a_index% := temp1
  pos := pos + strLen(temp1)
  displayword := word%a_index%
  msgbox %pos%`n%temp1%`n%sentence%`n%displayword%
}

^x::ExitApp


I get the output:
0

Test this sentence, okay?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 24th, 2009, 12:10 am 
Offline

Joined: October 7th, 2006, 4:50 pm
Posts: 3157
Location: MN, USA
Code:
sentence = Test this sentence, okay?
StringSplit, word, sentence, %A_Space%
Loop, %word0%
 MsgBox,% word%A_Index%


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 24th, 2009, 2:36 am 
Offline

Joined: February 17th, 2008, 7:09 am
Posts: 536
Before splitting the sentence by spaces, you may want to combine all the unwanted non-words and convert them to spaces. Since punctuation would get confused as words, unless that's not important.

Code:
newsentence := RegexReplace(sentence, "\W+", " ")
StringSplit, word, newsentence, %A_Space%


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 24th, 2009, 5:21 pm 
Offline

Joined: August 24th, 2005, 5:29 pm
Posts: 549
Location: Berlin / Germany
Code:
#NoEnv
sentence = Test this sentence, okay?
pos = 1
counter = 0
While (pos := RegExMatch(sentence, "[a-zA-Z]+", temp, pos + StrLen(temp)))
{
  counter++
  word%a_index% := temp
  displayword := word%a_index%
  MsgBox Word: %counter%`nPosition: %pos%`n%temp%`n%sentence%`n%displayword%
}
ExitApp
^x::ExitApp

_________________
nick :wink:


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Alpha Bravo, Google [Bot], rbrtryn, Yahoo [Bot] and 19 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group