AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Can you count how many chars are in a var?

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Eedis



Joined: 12 Jun 2009
Posts: 397

PostPosted: Sat Oct 17, 2009 7:22 am    Post subject: Can you count how many chars are in a var? Reply with quote

I want to count how many characters there are in a variable, then store that number as it's own variable...

Is this possible?

What I was wanting to do, a rough idea to maybe help you understand. I'm 'StringSplit'ing a long sentence, to get each seperate word. Then I want a loop to run, the amount of words there are in that sentence... Is that possible?
_________________
Pylons Are Trapped Balls.
http://www.autohotkey.net/~Eedis/
Back to top
View user's profile Send private message Visit poster's website
jethrow



Joined: 24 May 2009
Posts: 783
Location: Iowa, USA

PostPosted: Sat Oct 17, 2009 7:25 am    Post subject: Reply with quote

Code:
var := StrLen(string)

Rolling Eyes
_________________
AHKL, COM_L,Webpage Controls,Donate to AHK
Back to top
View user's profile Send private message
Eedis



Joined: 12 Jun 2009
Posts: 397

PostPosted: Sat Oct 17, 2009 7:28 am    Post subject: Reply with quote

I want to find how many words there are, not all characters.
_________________
Pylons Are Trapped Balls.
http://www.autohotkey.net/~Eedis/
Back to top
View user's profile Send private message Visit poster's website
jethrow



Joined: 24 May 2009
Posts: 783
Location: Iowa, USA

PostPosted: Sat Oct 17, 2009 7:31 am    Post subject: Reply with quote

Code:
string := "I want to find how many words there are, not all characters."
StringReplace, string, string, %A_Space%, %A_Space%, UseErrorLevel
var := ErrorLevel+1


Or, better yet:
Code:
RegExReplace(string, "\S+", "", var)

_________________
AHKL, COM_L,Webpage Controls,Donate to AHK
Back to top
View user's profile Send private message
SKAN



Joined: 26 Dec 2005
Posts: 7179

PostPosted: Sat Oct 17, 2009 8:02 am    Post subject: Reply with quote

Code:
; PhiLho www.autohotkey.com/forum/viewtopic.php?p=85660#85660
str = Recommended for new scripts due to its superior speed and reliability.
RegExReplace(str, "\w+", "", count)
MsgBox % count
Back to top
View user's profile Send private message
flak



Joined: 02 Oct 2009
Posts: 69

PostPosted: Sat Oct 17, 2009 8:06 am    Post subject: Reply with quote

Code:

StringSplit, OutputArray, InputVar
MsgBox % OutputArray0
Back to top
View user's profile Send private message
Z_Gecko
Guest





PostPosted: Sat Oct 17, 2009 8:06 am    Post subject: Reply with quote

Quote:
Then I want a loop to run, the amount of words there are in that sentence...
why not using a parsing-loop right away?
http://www.autohotkey.com/docs/commands/LoopParse.htm
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group