help

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
HIAC
Posts: 111
Joined: 11 Oct 2017, 17:59
Location: Republic of Serbia

help

23 Nov 2017, 14:43

Name = [Alex]

If name is does not contain anything between [] or does not contain [] at all
do something
else if name contains something in[] (e.g name: "[AB]Alex[AC]")
do something else

How can I do that?
User avatar
Spawnova
Posts: 554
Joined: 08 Jul 2015, 00:12
Contact:

Re: help

23 Nov 2017, 15:52

Code: Select all

;Example with name being valid
Name := "[AB]Alex[AC]"
nLength := strlen(name)
if (nLength > 2) {
	str := substr(name,2,nLength-2)
	msgbox % "Name = " str
} else {
	msgbox name does not contain data
}

;example with name being invalid
Name := "[]"
nLength := strlen(name)
if (nLength > 2) {
	str := substr(name,2,nLength-2)
	msgbox % "Name = " str
} else {
	msgbox name does not contain data
}
exitapp
HIAC
Posts: 111
Joined: 11 Oct 2017, 17:59
Location: Republic of Serbia

Re: help

23 Nov 2017, 16:47

Thanks, but in my case e.g. name "ab" should be valid and "[abc]" invalid..
burque505
Posts: 1732
Joined: 22 Jan 2017, 19:37

Re: help

23 Nov 2017, 16:52

@HIAC, @spawnova: How about this to take care of the case where the name isn't in brackets?
I put in an InputBox for testing.
Spoiler
EDIT: HIAC, just saw your post. Apparently I have it backwards. Let me fiddle with it.
REEDIT: I don't think I really understand what should be good input and bad input.
1) Is [Joe or Joe] good input? How about Sally[Carruthers?
2) How about Bill[the]Captain?
3) Will your script be prepending '[' and appending ']'?
RE-REEDIT: Ahah! I just saw your post at https://autohotkey.com/boards/viewtopic.php?f=5&t=40407, glad it's fixed.
Thanks!
Regards,
burque505
HIAC
Posts: 111
Joined: 11 Oct 2017, 17:59
Location: Republic of Serbia

Re: help

23 Nov 2017, 19:53

Well that code is not exactly what I was looking for but does what it's supposed to in some cases. Thanks!
Look, this is what I have:

Code: Select all

Name := "[AA]Monkey[CC]"
RegExMatch(Name, "\[\w+\]\K\w+", NameNoTag)
MsgBox % NameNoTag
So if Name is [Alex], result will be empty which is bad, as well as Bill[the]Captain because it will capture only Captain, and Sally[Carruthers won't capture anything..

If [AA]Banana = capture "Banana"
If [AA]Carrot[BB] = capture "Carrot"
If John[The]King = capture "John[The]King "
If [Alex] = capture "Alex"

thanks for your time! :)
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: help

24 Nov 2017, 12:08

As burque505 I guess your question is set against the background of this other thread.
If it is, you can, alternatively, use JSON files instead.

while standard ini file looks like:

Code: Select all

[section]
key=value
a basic json file could be:

Code: Select all

{
"section": {
	"key":"value"
}
}
One of the main adavntage of json formatted data against ini is also the possibilty to create 'subsections' and thus order hierarchically each datum:

Code: Select all

{
"section": {
	"subsection1": {
		"[AA]BB[CC]":"value"
	}
	,"subsection2": {
		"[AA]BB[CC]":"value"
	}
}
}
...and the fact that you can store/retrieve various type of values (boolean, arrays, objects etc.):

Code: Select all

{
"section": {
	"key":[ true, 0.11, null, "test", {"B":"Б","TS":"Ц"}]
}
}
I just updated my JSONData class with a working example using a key such as [AA]BB[CC]. However, you'll arguably find mine not easy to use since it mixes ahk and javascript syntax sometimes (which can be nonetheless very usefull in some case) and has the drawback to require parenthesis when dot syntax style (section.subsection1.key) and bracket syntax style (section["subsection1"]) are used together to store/retrieve data... I know that Coco made a pretty good one.
my scripts

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Billykid, Chunjee, Google [Bot], icyolive, Swiftly9767 and 301 guests