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?
help
Re: help
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
Some of my AHK programs: 3D Voxel Game - Platformer Game
GitHub projects : Image/Pixel scanning class - Direct2D overlay class
GitHub projects : Image/Pixel scanning class - Direct2D overlay class
Re: help
Thanks, but in my case e.g. name "ab" should be valid and "[abc]" invalid..
Re: help
@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.
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
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
Re: help
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:
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!
Look, this is what I have:
Code: Select all
Name := "[AA]Monkey[CC]"
RegExMatch(Name, "\[\w+\]\K\w+", NameNoTag)
MsgBox % NameNoTag
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!
Re: help
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:
a basic json file could be:
One of the main adavntage of json formatted data against ini is also the possibilty to create 'subsections' and thus order hierarchically each datum:
...and the fact that you can store/retrieve various type of values (boolean, arrays, objects etc.):
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.
If it is, you can, alternatively, use JSON files instead.
while standard ini file looks like:
Code: Select all
[section]
key=value
Code: Select all
{
"section": {
"key":"value"
}
}
Code: Select all
{
"section": {
"subsection1": {
"[AA]BB[CC]":"value"
}
,"subsection2": {
"[AA]BB[CC]":"value"
}
}
}
Code: Select all
{
"section": {
"key":[ true, 0.11, null, "test", {"B":"Б","TS":"Ц"}]
}
}
Who is online
Users browsing this forum: Billykid, Google [Bot] and 219 guests