jeeswg's strings tutorial

Helpful script writing tricks and HowTo's
User avatar
jeeswg
Posts: 1241
Joined: 19 Dec 2016, 01:58
Location: UK

jeeswg's strings tutorial

11 Jun 2017, 23:24

Please make any comments, or any requests/suggestions as to further content.

Do share any links that you found useful re. strings.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



==================================================

SUMMARY OF STRING FUNCTIONS/COMMANDS

(continuation sections) ['var = value' style continuation sections will not be present in AHK v2]
(if (var1 = var2)) [if statements without round brackets are deprecated]
(if var is type)
(var := expression) ['var = value' is deprecated)
[AutoTrim will not be present (or needed) in AHK v2]
[if var in/contains due to be replaced in AHK v2]
[Transform will not be present in AHK v2]
Chr/Ord [Asc is deprecated]
Format [SetFormat will not be present in AHK v2]
InStr [StringGetPos is deprecated]
RegExMatch/RegExReplace
StringCaseSense
StringLower/StringUpper [will be replaced with StrLower/StrUpper in AHK v2, Format can also change case]
StrLen [StringLen is deprecated]
StrPut/StrGet
StrReplace [StringReplace is deprecated]
StrSplit [StringSplit is deprecated]
SubStr [StringLeft/StringRight/StringTrimLeft/StringTrimRight/StringMid are deprecated]
Trim/LTrim/RTrim
VarSetCapacity

I would personally recommend that the following functions be added to AHK:
- StrContains/StrIn/StrStarts/StrEnds (or a versatile 'StrMatch' function) (note: 'if var in/contains' are due to replaced anyhow)
- StrRept
- StrCount (cf. StrReplace's OutputVarCount parameter)
Possibly also (one reason is for quick conversion from other programming languages):
- StrLeft/StrRight/StrTrimLeft/StrTrimRight

Note: users can create custom functions for these, however each would be unique to the user, and would require the function be included with the script, and it would be better to have one core function, where everyone knows how the function works, than to read through the code for various custom functions. Also some user-made custom functions might have drawbacks that an official function wouldn't have.

==================================================

KEY STRING FUNCTIONS/COMMANDS:

InStr()
https://autohotkey.com/docs/commands/InStr.htm
SubStr()
https://autohotkey.com/docs/commands/SubStr.htm
If var [not] in/contains value1,value2,...
https://autohotkey.com/docs/commands/IfIn.htm
If var is [not] type
https://autohotkey.com/docs/commands/IfIs.htm
[use StrSplit, StringSplit is deprecated]
StringSplit / StrSplit()
https://autohotkey.com/docs/commands/StringSplit.htm
StringLower / StringUpper
https://autohotkey.com/docs/commands/StringLower.htm
[use StrLen, StringLen is deprecated]
StrLen / StringLen
https://autohotkey.com/docs/commands/StringLen.htm
[continuation sections]
AutoHotkey Scripts and Macros
https://autohotkey.com/docs/Scripts.htm#continuation
Chr()
https://autohotkey.com/docs/commands/Chr.htm
[use Ord, Asc is deprecated]
Ord()
https://autohotkey.com/docs/commands/Ord.htm

further links:

Alphabetical Command and Function Index
https://autohotkey.com/docs/commands/
Format
https://autohotkey.com/docs/commands/Format.htm
Loop
https://autohotkey.com/docs/commands/Loop.htm
Arrays
https://autohotkey.com/docs/misc/Arrays.htm
RegExMatch
https://autohotkey.com/docs/commands/RegExMatch.htm
RegExReplace
https://autohotkey.com/docs/commands/RegExReplace.htm

==================================================

LINKS:

jeeswg's characters tutorial - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=7&t=26486

RegEx handy examples (RegExMatch, RegExReplace) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=7&t=28031

text/list/table functions - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=27023

jeeswg's objects tutorial - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=7&t=29232

[combine columns]
How to combine text of two seperate files in a new file - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=26127
[swap columns]
how to change the column A with the column B in Text file? - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=27721
Match entire line - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=32602
[choose/case]
Selecting a tab in another program - Page 2 - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=32717&p=152641#p152641

AutoHotkey Expression Examples: "" %% () and all that
http://www.daviddeley.com/autohotkey/xprxmp/autohotkey_expression_examples.htm

==================================================

NEW SECTIONS:

[2017-06-21] INSERT, OVERWRITE, IF VAR (NOT) STARTS LIST, IF VAR (NOT) ENDS LIST
[2017-06-23] SEARCH FROM THE NTH-TO-LAST CHARACTER BACKWARDS, SEARCH FROM THE NTH CHARACTER BACKWARDS
[2017-06-26] SENDINPUT (ESCAPING CHARACTERS)
Last edited by jeeswg on 27 Jun 2017, 07:26, edited 30 times in total.
User avatar
nnnik
Posts: 1985
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: jeeswg's strings tutorial

12 Jun 2017, 00:54

Generally speaking you advocate several techniques that I would not encourage people to use/learn.
Recommends AHK Studio
User avatar
jeeswg
Posts: 1241
Joined: 19 Dec 2016, 01:58
Location: UK

Re: jeeswg's strings tutorial

12 Jun 2017, 01:22

Please elaborate. I have been quite careful in what I have written here, so it is difficult to imagine what you could have in mind.
Helgef
Posts: 1646
Joined: 17 Jul 2016, 01:02

Re: jeeswg's strings tutorial

21 Jun 2017, 05:18

Thorough work, might be useful for those who like to learn by example. :thumbup:
Missing: StrPut and StrGet.

Cheers.
User avatar
jeeswg
Posts: 1241
Joined: 19 Dec 2016, 01:58
Location: UK

Re: jeeswg's strings tutorial

21 Jun 2017, 10:13

@nnnik: Any more details, or even an alternative strings tutorial are quite welcome. I do like to consider all viewpoints.

@Helgef: Cheers. I did include a little on StrGet and StrPut in the link below, I had thought of it more of an 'encoding' issue than a strings issue, but I will add it to this tutorial in one or two places, e.g. at least in a list of string functions/commands and also re. overwriting text, which StrPut is useful for.
jeeswg's characters tutorial - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=7&t=26486
User avatar
nnnik
Posts: 1985
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: jeeswg's strings tutorial

21 Jun 2017, 12:02

Oh I forgot
I only scammed the contents last time but it comes down to:

Code: [Select all] [Download] GeSHi © Codebox Plus

If var [not] in/contains value1,value2,...
https://autohotkey.com/docs/commands/IfIn.htm
If var is [not] type
https://autohotkey.com/docs/commands/IfIs.htm
Recommends AHK Studio

Return to “Tutorials”

Who is online

Users browsing this forum: Heezea and 11 guests